GDP2
GDP2

Reputation: 2018

How to change the speed of an object in Phaser without changing its direction

How do you change the speed of an object in phaser without changing its direction? For example, I have a ball that collides against a moving platform. I want the ball to change direction, but not gain any additional speed from the collision against a moving side of the platform. Up to now I have had to take the sign of the velocities of the object and then reapply a constant value speed to it on collision, but that seems quite wrong for a library as robust as Phaser is.

How do you modify speed and direction independently outside of velocity?

Upvotes: 4

Views: 1231

Answers (1)

Meg
Meg

Reputation: 1472

I've been using bounce to get that sort of effect in my games. Try using ball.body.bounce.set(1);.

From the docs:

The elasticitiy of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.

Upvotes: 1

Related Questions