[SOLVED] Bouncy Platforms

I’ve already come with questions about moving platforms and solved it, however, how would I go about making platforms that bounce the player upwards (or even in a certain direction.)

Hi @Overbaked! I think you can do this by applying a upwards force (impulse) on the rigidbody of the player when the collider of the player hit the collider of the platform.

https://developer.playcanvas.com/en/tutorials/collision-and-triggers/

I’m assuming specifying which way you’re bounced can be edited with the parameters of your applied impulse? I am also having a problem as there are no errors in the script this time, but, the model isn’t bouncing. So I’m wondering do I apply a line for the model and then the “player” itself.

Hello @Overbaked,

Yes, you can specify in what axis/axes the impulse is being applied in. You can read the documentation here.

Applying the impulse to the platform should suffice. Make sure that you are applying enough force if your platform is heavy.

I think the intention is the platform acts like a trampoline, so the impulse need to be applied on the player.

Ah, I see. In that case @Overbaked, please apply the impulse to the player, I’m sorry for misunderstanding. However, the rest of the points I made still apply(about the axes and the impulse being applied based on the mass).

How would I apply the impulse to the player?

var Bouncing = pc.createScript('bouncing');

// initialize code called once per entity
Bouncing.prototype.initialize = function() {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};

// update code called every frame
Bouncing.prototype.onCollisionStart = function (result) {
    if (result.other.rigidbody) {
        this.entity.sound.play("hit");
        this.entity.rigidbody.applyImpulse(0, 100 ,0);
    }
};
  1. Add this script to your platform.

  2. Change this.entity.rigidbody.applyImpulse(0, 100 ,0); to result.other.rigidbody.applyImpulse(0, 100 ,0);.

  3. Check the result.

Note: Remove the ‘play sound’ rule from your script if you don’t use it. Otherwise make sure you access the right entity to play the sound.

1 Like

I replaced the inputs, however, the platform will no longer appear. Did I do something wrong coding wise or something else?

Project Link: PlayCanvas 3D HTML5 Game Engine

NEVERMIND, I HAD THE WRONG SCRIPT ON IT, SORRY!

1 Like

I see it works. Good job!