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 :: unity new vector3 
Csharp :: get width of image unity 
Csharp :: c# regex find number in string 
Csharp :: get value from config file c# 
Csharp :: unity call function on animation onstateexit 
Csharp :: c# new object without class 
Csharp :: HOW TO RETURN CELL VALUE FROM EXCEL IN C# 
Csharp :: how to make text show a variable in unity 
Csharp :: csharp datagridview filter column 
Csharp :: c# read lines number 3 from string 
Csharp :: c# get directory name from filename 
Csharp :: difference between class and struct in c# 
Csharp :: c# write to output window 
Csharp :: count number of properties on an object C# 
Csharp :: c# enum default 
Csharp :: Squares of a Sorted Array 
Csharp :: c# execute shell command 
Csharp :: unity find child by name 
Csharp :: dotnet automapper.extensions.microsoft.dependencyinjection 
Csharp :: hcf of numbers 
Csharp :: difference between boxing and unboxing in java 
Csharp :: postasjsonasync reference c# 
Csharp :: multiplication of long number 
Csharp :: how to check if List<T element contains an item with a Particular Property Value in c# 
Csharp :: c# kill one excel process 
Csharp :: how get data from json in c# 
Csharp :: dynamic group by expression C# 
Csharp :: c# get gridview DataKeyNames 
Csharp :: how to add to a list only items that are not already in the list c# 
Csharp :: how to get the size an array in unity 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =