Reputation: 81
I have an small 3d game with a ball that are going only in front and jump. I want to stop the player movement when the ball are falling down but i don't know.
void FixedUpdate()
{
// Player movement
rb.transform.Translate(0, 0, forwardForce * Time.deltaTime,);
// What's happening when the ball fall down
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
Upvotes: 0
Views: 367
Reputation: 81
Worked with this code, thanks:
if (rb.position.y > -1f)
{
// Player Movement
rb.transform.Translate(0, 0, forwardForce * Time.deltaTime);
}
else
{
FindObjectOfType<GameManager>().EndGame();
}
Upvotes: 0
Reputation: 507
Try to use condition to check if the movement of the ball before moving the player.
void FixedUpdate()
{
// What's happening when the ball fall down
if (!(rb.position.y < -1f))
{
// Player movement
rb.transform.Translate(0, 0, forwardForce * Time.deltaTime,);
} else
{
FindObjectOfType<GameManager>().EndGame();
}
}
Upvotes: 1