- Home /
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...
Answer by kolban · Apr 10, 2012 at 09:57 PM
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.
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?
Your answer
Follow this Question
Related Questions
Ball jump on collision problem 1 Answer
android, roll a ball, using single touchpad to jump 1 Answer
I am having a problem trying to simulate football(soccer) physics 2 Answers
Simulating the graphics of a rolling 3D ball in a 2D game 2 Answers
How do I switch from Character player to Airship Vehicle using triggers? 0 Answers