Horje
unity 2d top down movement script Code Example
top down movement unity
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);
}
unity 2d top down movement script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{


    public float moveSpeed = 5f;

    public Rigidbody2D rb;

    Vector2 movement;

    // Update is called once per frame
    void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
    }

    void FixedUpdate()
    {
        rb.MovePosistion(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
    }
}




Csharp

Related
Find Center Of Transforms, Points, Multiple Objects Code Example Find Center Of Transforms, Points, Multiple Objects Code Example
c# gridview summary item displayformat Code Example c# gridview summary item displayformat Code Example
get number of sundays in a month c# Code Example get number of sundays in a month c# Code Example
change name of gameobject Code Example change name of gameobject Code Example
plays ervices unity sigin Code Example plays ervices unity sigin Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11