question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to lock the player's rotation so that he remains vertical at all times?

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
speekadievscommented, Sep 1, 2019

@roschler

You can set the inertia to infinity, and that should prevent your body from rotating.

Matter.Body.setInertia(body, Infinity);

2reactions
Sanuichcommented, Aug 26, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to lock the rotation of cylindrical components ... - YouTube
Innova Systems is an authorised Value Added Reseller for SOLIDWORKS 3D design software. Call us on 01223 200690.
Read more >
Lock rotation of object - Unity Answers
I've got a turret on a tank that follows the player. Unfortunately, it'll follow so strictly that if the player gets too close...
Read more >
Rotate the screen on your iPhone or iPod touch - Apple Support
Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that...
Read more >
iPhone Screen Not Rotating to Landscape Mode? Here's How ...
Here, tap on the Portrait Orientation Lock toggle (which looks like a lock with a circular arrow) to turn it on or off....
Read more >
Why is it 2022 and there still isn't a setting to lock the screen ...
1.1K votes, 133 comments. I am so tired of going to watch a video and rotating my phone, realizing that my screen is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found