Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

movement unity

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 ui 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 :: doing void when gameobject setactive unity 
Csharp :: how to make colliders collide with some things but not other in unity 
Csharp :: how return only value of array in laravel 
Csharp :: c# change label from thread 
Csharp :: initialize list in c# 
Csharp :: c# xor byte array 
Csharp :: remove adjacent duplicate characters 
Csharp :: binary search c# 
Csharp :: find character from string c# count 
Csharp :: C# function return datareader 
Csharp :: c# get folder path from file path 
Csharp :: unity instantiate prefab 
Csharp :: raylib c# 
Csharp :: c# space as string 
Csharp :: string to datetime c# 
Csharp :: length of array c# unity 
Csharp :: build cs file 
Csharp :: unity create empty gameobject in code 
Csharp :: asp.net core mvc jsonresult example 
Csharp :: c# read csv file 
Csharp :: how c# connection 
Csharp :: unity text custom color 
Csharp :: long number multiplication 
Csharp :: c# merge two xml files 
Csharp :: c# get property type of list 
Csharp :: if checkbox checked in c# 
Csharp :: how to define a function in c# 
Csharp :: C# new form 
Csharp :: ef core include 
Csharp :: map user to ConnectionId SignalR 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =