Ciuca Cristi
Ciuca Cristi

Reputation: 81

Unity 3d C# Stop player movement on death (falling down)

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

Answers (2)

Ciuca Cristi
Ciuca Cristi

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

Art Zolina III
Art Zolina III

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

Related Questions