“Einheit Topdown -Bewegung” Code-Antworten

Top -Down -Bewegung Einheit

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);
}
Graceful Grivet

Einheit Topdown -Bewegung

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);
 }
}
Levi Bills

Ähnliche Antworten wie “Einheit Topdown -Bewegung”

Fragen ähnlich wie “Einheit Topdown -Bewegung”

Weitere verwandte Antworten zu “Einheit Topdown -Bewegung” auf C#

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen