x


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?

more ▼

asked Aug 01 '10 at 05:24 AM

Troy gravatar image

Troy
32 8 8 9

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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).

more ▼

answered Aug 01 '10 at 07:28 AM

qJake gravatar image

qJake
11.6k 43 78 161

(comments are locked)
10|3000 characters needed characters left

The above didn't work in the script?

more ▼

answered Aug 25 '10 at 06:44 PM

Jim 3 gravatar image

Jim 3
1 1 1 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3344
x2507
x1537

asked: Aug 01 '10 at 05:24 AM

Seen: 1821 times

Last Updated: Aug 01 '10 at 05:24 AM