- Home /
Trampoline effect (low jump to high jump)
Hi, I want my player to start jumping close to the trampoline then gradually making it jump higher and higher.
Is this the right way to implement that effect or am I doing something wrong ?
void OnCollisionStay2D(Collision2D col)
{
for (jumpForce = 10; jumpForce < 100 ; jumpForce++)
{
if(col.gameObject.tag == "Ragdoll")
{
rigidbody2D.velocity = new Vector2 (0, jumpForce);
}
}
}
Answer by fafase · Jul 11, 2014 at 06:07 PM
The trampoline effect is just that the more force there is on the object, the more force the trampoline will apply back.
You can consider at rest the trampoline gives:
force *= 0.8f
so that your guy slowly stops.
Now you can have an acceleration stage where the trampoline gives:
force *= 1.2f
Finally, if not resting nor accelareting then you just use force as 1.
The force is used to send the guy back up:
rigidbody2D.AddForce(transform.up * force);
Your guy will naturally go higher and higher, so you may want to clamp the force so that it gets to a max height (you can define that value based on mass, height of player, skills).
The rest is just visual effect where you stretch the trampoline up and down.
Your answer
Follow this Question
Related Questions
rigidbody.Addforce the force doesnt apply? 1 Answer
Multiple Cars not working 1 Answer
Interpolate problem? Jump isn't smooth... 1 Answer
Distribute terrain in zones 3 Answers
Preventing Rotated Jumping (C#) 1 Answer