Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity joystick movement

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class 2dMovement : MonoBehaviour
{
  //This also works with joystick, PS this is topdown movement

 private Rigidbody2D rb;
 public float MoveSpeed = 15f;


 void Start ()
 {
   rb = GetComponent<Rigidbody2D>(); 
 }

 void Update ()
 {
    private float vertical;
    private float horizontal; 
 
    horizontal = Input.GetAxisRaw("Horizontal");
    vertical = Input.GetAxisRaw("Vertical"); 
 }

 private void FixedUpdate()
 {  
    rb.velocity = new Vector2(horizontal * MoveSpeed, vertical * MoveSpeed);
 }
}
Comment

unity joystick movement

//You can do something like applying a force to a rigidbody or do something like this

        float singleStep = 1f * Time.deltaTime;
        Vector3 LookDir = new Vector3(LookJoystick.Horizontal, 0, LookJoystick.Vertical);
        Vector3 newDirection = Vector3.RotateTowards(transform.forward, -LookDir, singleStep, 0.0f);
        transform.rotation = Quaternion.LookRotation(+newDirection);//but that has limits

also make sure you have this asset installed
Comment

PREVIOUS NEXT
Code Example
Csharp :: untiy instanciate prefab 
Csharp :: reverse a string in c# 
Csharp :: decalre an int list mvc 
Csharp :: remove comma from string c# 
Csharp :: palindrome number c# 
Csharp :: instantiate unity 
Csharp :: c# build string out of list of strings 
Csharp :: how to set the frame rate unity 
Csharp :: c# return switch 
Csharp :: Open another form with C# Winforms 
Csharp :: c# list subfolders 
Csharp :: get roaming folder c# 
Csharp :: unity c# log an error or warning 
Csharp :: vb.net console log 
Csharp :: how to close an application in c# 
Csharp :: linq from select 
Csharp :: get description from enum c# 
Csharp :: c# cast to int 
Csharp :: c# is in array 
Csharp :: arrays in c# 
Csharp :: c# inline array initialization 
Csharp :: unity cast int to float 
Csharp :: hide button unity 
Csharp :: what is the meaning of ?? in c# 
Csharp :: debug.log 
Csharp :: instantiate unity 2d in parent 
Csharp :: array join c# 
Csharp :: wpf arrow button 
Csharp :: c# if statement 
Csharp :: how to set picturebox width with form width in c# 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =