Lina Dev
Lina Dev

Reputation: 15

Need a bounce from the direction of the player

I need the bounce of an object when it collides with the player depending on the direction of the player.

Upvotes: 0

Views: 59

Answers (1)

Voidsay
Voidsay

Reputation: 1550

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

Upvotes: 1

Related Questions