Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

error

using UnityEngine;


public class PlayerMovement : MonoBehaviour

{


    public Rigidbody rb;


    public float ForwardForce = 2000f;

    public float sidewaysForce = 500f;


    // Update is called once per frame

    void FixedUpdate()

    {

        rb.AddForce(0, 0, ForwardForce * Time.deltaTime);


        if (Input.GetKey("d"))

        {

            rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);

        }


        if(Input.GetKey("a"))

        {

            rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);

        }


        if (Input.GetKey("left"))

        {

            rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);

        }


        if (Input.GetKey("right"))

        {

            rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);

        }


        if (rb.position.y < -1f)

        {

            FindObjectOfType<GameManager>().EndGame();

        }



    }

Sign In or Register to comment.