schmevie15

Rotating a square on a hill

Recommended Posts

Hey all I have this square I am rotating in my simple plat former and it moves along the straight ground perfectly. I am using:

enemy.body.rotateLeft(450);

This rotates the enemy perfectly, and moves it along, but I also have these hills in my game and when the enemy square encounters the hill it has a terrible time trying to get up it. Is there some sort of property that I can set that would help with this perhaps mass? Or any ideas on how to resolve this? Thanks!

P.S I've attached a picture of the square on the hill for reference. Thanks!

Screen Shot 2016-04-15 at 1.42.08 PM.png

Share this post


Link to post
Share on other sites
22 minutes ago, schmevie15 said:

Hey there thanks for the answer! 
im not sure exactly what you mean though? 
Should I use anchor.setTo to set the anchor/pivot point, 
And then how can I rotate manually??

Thanks!

Hey,

I think (not sure) that the difference between pivot and anchor is that the pivot does not change the position of the sprite. So set the pivot to 1,1 initially. Rotate 90 degrees (the sprite), Change the pivot to the new point (1,0). I have drawn a picture, hope it helps and you make it work.

By manually, I mean directly to the sprite, without physics. If you can't make it work and are willing to share your code, i can try to play with it a bit in my spare time.

 

 

 

squares.png

Share this post


Link to post
Share on other sites

You basically want to enable slopes in arcade physics?

Its possible, I did something like this with bitmap data, but I would just get two points some how (based on your logic) and then set the angle to the sprite.

Share this post


Link to post
Share on other sites

I see what the problem is. 

As you have already made it work very well, I would just suggest that you use a variable inside your rotateLeft method. If you are on a steep slope the variable will be higher, if you are on a straight line it can be 450 (mby smaller if you are going downhill). You can change it manually, depending on the position of your enemy. How does that sound? 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.