Home > database >  Need a bounce from the direction of the player
Need a bounce from the direction of the player

Time:08-08

I need the bounce of an object when it collides with the player depending on the direction of the player. Just like the trees bounce off the player here: https://youtube.com/clip/UgkxVFvZZixbKJWaZInqQlccWWAkc3jJPgFS

Current position and expected position

CodePudding user response:

Adding a force to the tree in the direction from the player to the tree should do it.

Vector3 dir = treeTransform.position - playerTransform.position;
treeRb.AddForce(dir*force, ForceMode.Impulse);

If the origin of the tree is off center or the tree doesn't tilt enough you can also use AddForceAtPosition

  • Related