Answer the question
In order to leave comments, you need to log in
How to stop an object when it reaches a certain coordinate?
How to stop an object when it reaches a certain coordinate? For example, Y needs to stop the object. I give the object an impulse, upon reaching the value 0, I would like the object to stop. However, when pressed, the object should continue to move.
if(transform.position.y.Equals(0))
{
if(Input.GetKeyDown(KeyCode.Space))
{
playerRb.AddForce(Vector3.forward * playerSpeed, ForceMode.Impulse);
}
}
Answer the question
In order to leave comments, you need to log in
Found a solution if anyone needs it
if(transform.position.y.Equals(0))
{
playerRb.constraints = RigidbodyConstraints.FreezePosition;
if (Input.GetKeyDown(KeyCode.Space))
{
playerRb.constraints = RigidbodyConstraints.None;
playerRb.AddForce(Vector3.up * playerSpeed, ForceMode.Impulse);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question