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 :: unity topdown 
Csharp :: c# how to write an array in a single line 
Csharp :: how to make a mouse down condition in unity 
Csharp :: difference between iqueryable and ienumerable c# 
Csharp :: dotnet new project 
Csharp :: c# integer to bit string 
Csharp :: onkeypressed unity 
Csharp :: polybius square 
Csharp :: convert string into double in c# 
Csharp :: how to remove all buttons on a form C# 
Csharp :: list all files in directory and subdirectories c# 
Csharp :: how to store array in c# 
Csharp :: send type as argument c# 
Csharp :: implement custom string to datetime convert net core 
Csharp :: c# 2d list 
Csharp :: unity key down 
Csharp :: unity icons 
Csharp :: how to remove vowels from a sttring using regex c# 
Csharp :: c# list slice 
Csharp :: how to check if a path is a directory or file c# 
Csharp :: char contains c# 
Csharp :: how to open website from c# program 
Csharp :: unity play sound effect 
Csharp :: check if internet is connected with c# winforms 
Csharp :: coroutine start unity 
Csharp :: c# random sleep 
Csharp :: c# swtich 
Csharp :: get current time c# 
Csharp :: github action get commit tag 
Csharp :: c# create console for winform 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =