Jump to content

Simple movement with P2 and my character rotates


TheSisb
 Share

Recommended Posts

My game: http://antipeasantry.com/PhaserGame/index.html

 

If I move my character to the bottom left corner of the world and start banging into the edge then moving back out while (Somewhat) wildly mashing on directional keys, the sprite begins to rotate ever so slightly.

 

I want to keep it locked to 8 directions: left, topleft, top, topright, right, bottomright, bottom, bottomleft and avoid any rotations.

 

Any advice is appreciated! Thanks

Link to comment
Share on other sites

I can replicate your problem, looks like angular velocity has been added to your physics body, and it also looks like there is no damping force to stop it.

 

Further, it looks like maybe the problem is the collision. When objects collide friction (and some other stuff) causes angular forces to be exerted upon them, these forces are usually dissipated by damping forces in simulations.

 

So, I think a couple of things, or a combination of them, might help you out:

 

Whack up the `angularDamping` to 1 (I think that is max), which means thats any angular momentum is immediately damped to 0.

Check out your `contactMaterials`, the contact materials set some factors of what happens when different materials collide, setting friction to 0 or 1 (min or max, I cant remember which way round you need).

 

Oh, for some reason I assumed you were using P2 for physics, Phaser supports other physics engines, I only have working knowledge of p2 but its quite possible the theory remains for the other 2 phaser implements (ninja and arcade I think)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...