Wired bug of thrust rotation (Transform.Rotate() Our Rocket video)

i’m working in Unity 2021.3.2f1 and i’m having this weird bug-when i press play and hit my space bar it Either lets me do it a few times but gives very little thrust or gives me only one time and gives a powerful thrust- i kept the Debug.log and that is keep counting when i hit space.
the numbers of my mass are 1 and my mainThrust is 1000 just like in the video.
the rotation seem to work differently too and give me just a small sharp tilt
adding my code so you could see-

public class Movement : MonoBehaviour

{

 [SerializeField] float mainThrust = 100f;

 Rigidbody rb;

// Start is called before the first frame update

void Start()

{

   rb = GetComponent<Rigidbody>();

}

// Update is called once per frame

void Update()

{

  ProcessThrust();

  ProcessRotation();

}



void ProcessThrust()

{

  if (Input.GetKeyDown(KeyCode.Space))

   {

   Debug.Log("Thrust");

    rb.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);

   }

}

void ProcessRotation()

{

  if (Input.GetKeyDown(KeyCode.A))

   {

    // Debug.Log("Rotate Left");

    transform.Rotate(Vector3.forward);

   }    

  else if (Input.GetKeyDown(KeyCode.D))

   {

    // Debug.Log("Rotate Right");

    transform.Rotate(-Vector3.forward);

   }

}

}

Found it
i had GetKeyDown insted of GetKey :sweat_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms