How to lock the player's rotation so that he remains vertical at all times?
See original GitHub issueI want to keep the player sprite vertical at all times, regardless. Right now, if it comes in contact with certain objects it tips over on its side. I found a lot of documents on the web related to this, but I’m having a recurrent problem with the documents I find using the primary Matter
namespace. The examples in those documents don’t match interfaces I find with inspecting the matter
property attached to a Phaser 3
object. When I try the techniques described in the Matter
namespace documents they don’t work, usually with the demonstrated property being undefined
.
I tried manually setting the angle
property attached to the player body
property, but Matter JS appears to interpret that sudden change in angle as a massive velocity event and sends the player sprite flying off the visible world:
player.body.angle = 0;
I tried setting the player’s inertia to infinity, but then it won’t move:
player.body.setInertia('Infinity');
How can I keep the player always vertical?
Also, if someone could point me to a document that explains how to use Matter JS specifically when operating in the Phaser JS environment, I’d really appreciate it. I’ve lost literally days learning how to do various operations that should have been straightforward. For example, I still haven’t figured out how to access the Matter-JS SAT module from within a Phaser 3 app so I can do advanced collision detection like detecting when my player is colliding with any game objects or not. The matter
property attached to the Phaser 3 instance does not have a SAT property.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
@roschler
You can set the inertia to infinity, and that should prevent your body from rotating.
Matter.Body.setInertia(body, Infinity);
wow unanswered qustion. not good, not good…
U can set angle every tick Events.on(engine, ‘afterUpdate’, function(){player.body.angle = 0;});
i would do some extra options in this library if i where developer