- Home /
How do i make a Character/object bounce using Javascript?
what javascript can i use? and will the bounce script work with other objects aswell as the character?
Iv had an answer previous but im still finding it hard to set the bounce on an object.
thanks for the support !
Answer by efge · Jan 14, 2011 at 10:34 PM
You could add an collider, assign a physics material and set its bounciness to 1.
Look at the Standard Assets/Physic Materials folder in your project. There are some example materials (There is also one called "Bouncy".). One of the properties is bounciness.
The collider depends on your mesh geometry. For a ball you should use a sphere collider.
how do you cange bounciness? i can't see the option plus what kind of collider do i add?
Answer by levettmw · Sep 15, 2012 at 12:41 AM
I have been using this #pragma strict var firstTimeVelocitySave = false; var savedVelocity : Vector3; var myRigidbody : Rigidbody; var BounceRate:float =1.5;
function OnCollisionEnter(col : Collision) { //print("Collision! " + rigidbody.velocity);
if (! firstTimeVelocitySave) { savedVelocity = rigidbody.velocity; firstTimeVelocitySave = true; } myRigidbody.velocity.y = savedVelocity.y; savedVelocity.y=savedVelocity.y/BounceRate; }
Your answer
Follow this Question
Related Questions
Ball Bounce with Random Range 1 Answer
Ping Pong Reflect 2 Answers
Make a ball jump on plane collision 1 Answer
Rigidbody jump adds bounce energy to second jump 1 Answer
How to make an unrealistic bounce? 3 Answers