x


Make a ball jump on plane collision

I want a ball to fly up when it hits a plane in javascript. The action would be similar to the ball rolling over a burst of air, where the force is upwardly...

more ▼

asked Apr 10 '12 at 09:07 PM

valichm gravatar image

valichm
136 19 22 27

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

1 answer: sort voted first

Create yourself a cube that is not rendered and flagged as a trigger only. Place this cube where you want the ball to be "affected" by the air jet. In your ball gameObject, attach a script which has code similar to the following:

function OnTriggerEnter(other:Collider)
{
   rigidbody.AddForce(Vector3.up * 20, ForceMode.Impulse);
}

What this code says is that when the ball enters a trigger area, an instantaneous impulse force will be applied in the "up" (Y Axis) direction. I tried this out and it worked like a champ.

more ▼

answered Apr 10 '12 at 09:57 PM

kolban gravatar image

kolban
1.8k 2 7

thank you! worked like a champ for me as well...

Apr 10 '12 at 10:50 PM valichm

how can I make it so that this object can still be destroyed when the ball collides with it? in other words, is there a way to add a script like this to an object and not a trigger?

Apr 11 '12 at 07:33 PM valichm
(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:

x3444
x1864
x335
x168

asked: Apr 10 '12 at 09:07 PM

Seen: 808 times

Last Updated: Apr 11 '12 at 07:33 PM