wasd movement unity 3d code example

Example 1: unity wasd movement

using UnityEngine;

public class Example : MonoBehaviour
{
    public int speed;

    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 Movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        this.transform.position += Movement * speed * Time.deltaTime;
    }
}

Example 2: unity movement wasd c#

using UnityEngine

public class Example : MonoBehaviour
{

public float speed = 10;
public Transform object;

	public void Update()
	{
    	float horizontalInput = Input.GetAxis("Horizontal");
    	float verticalInput = Input.GetAxis("Vertical");

    	Vector3 movement = new Vector3(horizontalInput, verticalInput, 0);
    	movement = movement.normalized * speed * Time.deltaTime;

    	object.transform.position += movement;
	}

}