- Home /
Trying to make a bounce platform that tosses the player.
I want to make a bounce platform. I tried to figure it out myself but no luck. I got it to work somewhat, but for some reason it would only work if I entered the trigger from the left side. So after trying different things this is what I have right now and its not doing anything. This is probably the wrong way to do it, so any suggestions would help.
public float bounciness;
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
GameObject player = GameObject.FindGameObjectWithTag("Player");
player.GetComponent<Rigidbody2D>().AddForce(Vector2.up, ForceMode2D.Force);
}
}
Answer by JustFun · Aug 19, 2014 at 02:30 PM
Uncheck IsTrigger checkbox in collider settings, check IsKinematic and FixedAngle in rigidbody 2D settings. Change the code:
public float bounciness; // Determines jump height
void OnCollisionEnter2D(Collision2D other)
{
other.rigidbody.AddForce(new Vector2(-other.relativeVelocity.x, other.relativeVelocity.y) * bounciness, ForceMode2D.Impulse);
// set x value of new force vector to 0.0f, if you need the jump was straight up
}
Ok It's working. But when if i jump on it over and over, each time i get thrown further and further.
This happens when bounciness > 1. If you need player jump up to fixed height, then force vector must be Vector2.up with multiplier:
other.rigidbody.AddForce(Vector2.up * bounciness, Force$$anonymous$$ode2D.Impulse);