top down movement unity
C#
public float Speed = 5f;
private void Update()
{
var input = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0);
Vector3 velocity = input.normalized * Speed;
transform.position += velocity * Time.deltaTime;
}public float Speed = 5f;
private void Update()
{
input = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0);
Vector3 velocity = input.normalized * Speed;
transform.position += velocity * Time.deltaTime;
}Rigidbody2D body;
float horizontal;
float vertical;
float moveLimiter = 0.7f;
public float runSpeed = 20.0f;
void Start ()
{
body = GetComponent<Rigidbody2D>();
}
void Update()
{
// Gives a value between -1 and 1
horizontal = Input.GetAxisRaw("Horizontal"); // -1 is left
vertical = Input.GetAxisRaw("Vertical"); // -1 is down
}
void FixedUpdate()
{
if (horizontal != 0 && vertical != 0) // Check for diagonal movement
{
// limit movement speed diagonally, so you move at 70% speed
horizontal *= moveLimiter;
vertical *= moveLimiter;
}
body.velocity = new Vector2(horizontal * runSpeed, vertical * runSpeed);
}
Also in C#:
- Title
- c# download string url
- Category
- C#
- Title
- get enum value c#
- Category
- C#
- Title
- unity string format time
- Category
- C#
- Title
- c# cheat sheet
- Category
- C#
- Title
- get set c#
- Category
- C#
- Title
- c# contextswitchdeadlock
- Category
- C#
- Title
- how to reference function in unity
- Category
- C#
- Title
- no overload for 'useItemOnSceneLoad' matches delegate 'UnityAction<Scene, LoadSceneMode>'
- Category
- C#
- Title
- order by C#
- Category
- C#
- Title
- decimal to string whole number c#
- Category
- C#
- Title
- c# find element by condition
- Category
- C#
- Title
- c# request run as administrator
- Category
- C#
- Title
- epplus excel vb.net
- Category
- C#
- Title
- isInstanceOf nunit
- Category
- C#
- Title
- how to locate a specific element in a list c#
- Category
- C#
- Title
- how to a equall to b in c#
- Category
- C#
- Title
- c# get executable path
- Category
- C#
- Title
- asp.net core timeout
- Category
- C#
- Title
- condition when a animation finishes in unity
- Category
- C#
- Title
- unity gizmo draw line
- Category
- C#
- Title
- c# summary tag
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- c# if statement
- Category
- C#
- Title
- c# long to int
- Category
- C#
- Title
- unity how to see what scen you are in
- Category
- C#
- Title
- c# mixed multidimensional array
- Category
- C#
- Title
- variables
- Category
- C#
- Title
- c# fileupload example
- Category
- C#
- Title
- Move player on planets in unity 2d
- Category
- C#
- Title
- c# reverse a string
- Category
- C#
- Title
- array syntax c#
- Category
- C#
- Title
- Unity C# instantiate prefab
- Category
- C#
- Title
- unity input get axis
- Category
- C#
- Title
- json serialize object capitalization config
- Category
- C#
- Title
- c# list tuple
- Category
- C#
- Title
- interpolate rotation unity3d
- Category
- C#
- Title
- while loop check condition c#
- Category
- C#
- Title
- trello
- Category
- C#
- Title
- c# print expression tree
- Category
- C#
- Title
- convert number of days into months c#
- Category
- C#
- Title
- c# iterate over string
- Category
- C#
- Title
- linq query select top 1 c#
- Category
- C#
- Title
- unity rotate towards mouse
- Category
- C#
- Title
- unity set material
- Category
- C#
- Title
- jump script unity 2d
- Category
- C#
- Title
- c# for loop without increment
- Category
- C#
- Title
- console application in c# ms crm
- Category
- C#
- Title
- add variable to the beginning of a list c#
- Category
- C#
- Title
- Length = '((System.Net.RequestStream)RequestStream).Length' threw an exception of type 'System.NotSupportedException'
- Category
- C#
- Title
- modificare una strinfa in c#
- Category
- C#
- Title
- what is type unity
- Category
- C#
- Title
- unity load scene
- Category
- C#
- Title
- clear combobox c#
- Category
- C#
- Title
- copy a list C#
- Category
- C#
- Title
- Instantiate c#
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- unity fps counter
- Category
- C#
- Title
- freeze position unity c#
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- matplotlib measure the width of text
- Category
- C#
- Title
- c# foreach namevaluecollection
- Category
- C#
- Title
- copy a list in c# unity
- Category
- C#
- Title
- move character unity
- Category
- C#
- Title
- .net core identity get user id
- Category
- C#
- Title
- iterate through dictionary c#
- Category
- C#
- Title
- c# making a folder
- Category
- C#
- Title
- unity cycle children
- Category
- C#
- Title
- compile in one single exe c#
- Category
- C#
- Title
- fly cam extended script unity 3d
- Category
- C#
- Title
- how to redirect to extern page in .net core
- Category
- C#
- Title
- c# polymorphism
- Category
- C#
- Title
- c# find duplicates in list
- Category
- C#
- Title
- optional parameter get request c#
- Category
- C#
- Title
- add new page to site c# programmatically
- Category
- C#
- Title
- grab reference from method parameter c#
- Category
- C#
- Title
- unity rigid body variable
- Category
- C#
- Title
- how to change scenes in unity
- Category
- C#
- Title
- void start
- Category
- C#
- Title
- C# for
- Category
- C#
- Title
- No IUserTwoFactorTokenProvider<TUser> named 'Default' is registered.'
- Category
- C#
- Title
- how to detect if a key is pressed in c#
- Category
- C#
- Title
- c# change label forecolor code
- Category
- C#
- Title
- unity remove gameobject
- Category
- C#
- Title
- c# create new object
- Category
- C#
- Title
- comments unity c#
- Category
- C#
- Title
- unity load text resources from subfolder
- Category
- C#
- Title
- microsoft.portable.csharp.targets was not found vs 2019
- Category
- C#
- Title
- unity find object by name
- Category
- C#
- Title
- convert system.byte a string c#
- Category
- C#
- Title
- covert char[] to string C#
- Category
- C#
- Title
- xarray: create 2d dataset
- Category
- C#
- Title
- add getenumerator to class c#
- Category
- C#
- Title
- linq in c#
- Category
- C#
- Title
- How to look at an object unity
- Category
- C#
- Title
- c# md5 int
- Category
- C#
- Title
- write string multiple times c#
- Category
- C#
- Title
- dynamic in c#
- Category
- C#
- Title
- how to allow user import image c#
- Category
- C#
- Title
- how to deactivate objects through scripts in unity
- Category
- C#
- Title
- set int to null c#
- Category
- C#