- Home /
How to hit gameobjects to go into the opposite direction of hit?
I'm making a third person game and I'm trying to make a mechanic like baseball or tennis where when you hit the ball it goes in the direction of where you hit it. I made an empty child of the players hand and attached capsule collider to it. I have an animation where the player swings arm and I want to make so that if the ball collides with the empty object it goes in the other direction.
Answer by Crumpet · Feb 10, 2019 at 01:13 AM
if you want it to go towards a specific position then get a vector3 which will be your target direction. get the position vector3 from where the object you want to hit currently is then do something like below
rigidbody.addforce( (targetdirection - currentposition).normalized * force);
or if you just want it to collide and launch it using physics just put colliders on your objects really.
Your answer
Follow this Question
Related Questions
Is there a way to have rigid bodies collide, but not transfer any force? 2 Answers
Object shattering under a certain weight/force 3 Answers
Make AI run from Player 1 Answer
Gravitational Object Creation for 3D Game 1 Answer
Collider question 0 Answers