- Home /
Apply opposite force on mouse-click + collision
Hi
I'm trying to create something where the aim is for the player to hit a ball-object.
It's first person so there will be a bat object visible, when the player clicks I want to test if there is a ball-object near and if so, apply a force to the ball in a negative direction.
How do I go about doing this?
Answer by qJake · Aug 01, 2010 at 07:28 AM
To completely reverse an object's velocity, just do this:
rigidbody.velocity = -rigidbody.velocity;
That will make it reverse mid-air. After that, you could apply variance to the vector, or use rigidbody.AddForce to make the ball move in a slightly different direction (akin to baseball).
Your answer
![](https://koobas.hobune.stream/wayback/20220613070203im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scripted Door w/ Line of Sight 1 Answer
Destroy Turret with machine Gun 0 Answers
Help with making item invisible if not on screen 1 Answer
Accessing Script that Raycast hit 3 Answers
Score keeping script 3 Answers