- Home /
"Rebound" effect when the character jump on an ennemy
Hello,
I am a member of a team working on a 2.5D plarformer. We got most of our mechanics working, but for some reason we are completely unable to add a "rebound" effect when the Player Character jump on an ennemy.
Since a Character Controller can't be affected by physics, using the "bouncy" material is out of the question.
How would you script a "rebound" effect for the Character Controller?
We are really new to scripting and game creation, so sorry if the answer is obvious.
Answer by · Sep 01, 2010 at 02:50 AM
Along the same lines as Will's suggestion, you could try just inverting the Y-axis velocity, or explicitly set it to a value.
The scripting reference for RigidBody.Velocity suggests:
In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour
However, that may not be an issue for you here (depending on style of game, and the gameplay outcomes, etc)
If you want to rebound based on how fast you are falling, you could try something like:
rigidbody.velocity.y = -rigidbody.velocity.y * 0.8;
This would mean that if the player character was moving (down) on the y axis at 10 m/s, they would be instantly set to bounce up at 8 m/s.
If you wanted reliable bounces, you could explicitly set it to a value.
** This may not be the best way, but I don't think using the relativeVelocity is ideal for typical 2.5D platformer behaviour.
Answer by Will 7 · Sep 01, 2010 at 02:32 AM
Well I am new too, but have you tried finding the velocity of the player and then on collision reversing it into a negative?
on collision{ rigidbody.velocity.y = (collision.relativeVelocity-(collision.relativeVelocity*2)) rigidbody.velocity.x = (collision.relativeVelocity-(collision.relativeVelocity*2)) } No idea if this would work or not but it might be worth a try.
Your answer
Follow this Question
Related Questions
Control Mid-Air Movement With Character Controller 1 Answer
A more realistic jump using CharacterController -1 Answers
Turning a rigidbody controller into a character controller (almost) 1 Answer
Rigidbody2d not falling once in the air 1 Answer
Can a character controller collide with a trigger? 2 Answers