简体   繁体   English

如何在不改变方向的情况下更改Phaser中对象的速度

[英]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. 到目前为止,我不得不采取对象速度的符号,然后在碰撞时重新应用恒定的速度,但对于像Phaser一样强大的库来说,这似乎是错误的。

How do you modify speed and direction independently outside of velocity? 如何在速度之外独立修改速度和方向?

I've been using bounce to get that sort of effect in my games. 我一直在使用bounce来在游戏中获得那种效果。 Try using ball.body.bounce.set(1); 尝试使用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. bounce.x / y = 1表示完全反弹,弹跳.x / y = 0.5表示反弹速度为50%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM