- Home /
Creating a bounce effect?
I am creating a game where the player must climb to the top by bouncing on the floating platforms. I wish to have it so when the player hits the platform they will bounce up x units. The code I had:
var bounce : int = 10;
function OnCollisionEnter (other : Collision) { if(other.gameObject.tag == "Bounceable") { transform.position.y = bounce * Time.smoothDeltaTime; } }
does not work correctly. As soon as the player hits the defined object he just appears 10 units above the object, with no smooth jumping effect at all. I also want to be able to control the character on his way up and back down but I do not know how to do this as it just teleports.
Answer by qJake · May 16, 2010 at 12:35 AM
You want to use something like Rigidbody.AddForce. This will let you "push" the object upwards using a force value you specify. Be sure to change the ForceMode to something like Impulse (basically burst-force), otherwise you won't notice it at all.
You could also set the Rigidbody's velocity manually, specifying a velocity of something like (0, -10, 0) to make it move in an upwardly direction.
Works perfectly, thank you! I changed it so ins$$anonymous$$d of transfor$$anonymous$$g the position in the OnCollisionEnter function i simply had it make a boolean true in the fixedupdate so it would work right.
Answer by poncho · Dec 21, 2010 at 09:46 PM
the problem about using, adding force or modifying velocity is that only works for the horizontal or vertical collisions, when you try to make it collide with a pline like 45 / or \ there goes a lot of problems cuz there is need for sin and cos equations and some other vector stuff, the unity physics for the bounce can be add in this way
Asset>Create>Physics Material, then to the object change the bounciness to a value more than 0 and drag the new material to the object you want to make it bounce,
the problem with this is that if you lauch an object it will stop in a few bounces cuz there are alot of things as friction, drag, angular drag, mass that stop it
hope it help
Answer by condorbox · Apr 25, 2019 at 02:50 PM
You can create a Physics material and change the Bouncing
Your answer
Follow this Question
Related Questions
Making Pong 1 Answer
Bouncing objects and Energy loss 2 Answers
Bounce with speed 1 Answer
perfect bounce when a bullet hits a wall 1 Answer
I wanna setup something like Kinematic option on sphere but with collision checker. 0 Answers