Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

2d topdown 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

PREVIOUS NEXT
Code Example
Csharp :: c# how to write an array in a single line 
Csharp :: how to change the axis of a Vector3 variable 
Csharp :: destroy game object 
Csharp :: mute sound unity 
Csharp :: how to make a custom cursor in windows forms c# 
Csharp :: c# get pressed key 
Csharp :: cannot convert from string to type T 
Csharp :: parse json array c# 
Csharp :: c# get getter set setter method 
Csharp :: c# textbox numbers only 
Csharp :: xamarin hide back button 
Csharp :: c# itext 7 pdf add pdf 
Csharp :: unity log error 
Csharp :: unity object change sprite 
Csharp :: serilog minimum log level 
Csharp :: why v-slot not working in vue 3 
Csharp :: C# type cast float to string 
Csharp :: C# get md5 of file 
Csharp :: c# dictionary to json 
Csharp :: c# enum to int array 
Csharp :: console.writeline in c# 
Csharp :: get out of foreach statement c# 
Csharp :: how to import datagridview to datatable in c# 
Csharp :: Configure Automapper 
Csharp :: shorthand if c# 
Csharp :: rock paper scissors c# 
Csharp :: C# add two numbers using a method 
Csharp :: linq get a dictionary key and value c# 
Csharp :: basic auth swagger .net core 5 
Csharp :: C# monogodb 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =