Answers for "unity 3d first person movement look around"

C#
1

unity 3d first person movement look around

public Rigidbody rb;
    public float MouseSensitivity;
    public float MoveSpeed;
    public float JumpForce;

    void Start ()
    {
        //Cursor.visible = false;
    }

    void Update()
    {
        //Look around
        rb.MoveRotation(rb.rotation * Quaternion.Euler(new Vector3(0, Input.GetAxis("Mouse X") * MouseSensitivity, 0)));

        //Move
        rb.MovePosition(transform.position + (transform.forward * Input.GetAxis("Vertical") * MoveSpeed) + (transform.right * Input.GetAxis("Horizontal") * MoveSpeed));
        
        //Jump
        if (Input.GetKeyDown("space"))
            rb.AddForce(transform.up * JumpForce);
    }
Posted by: Guest on February-18-2021

C# Answers by Framework

Browse Popular Code Answers by Language