Sign in to follow this  
sistemlogikadigital

[Noob Question] Rotate toward mouse cursor

Recommended Posts

How to rotate an object toward mouse cursor?

so far i tried this code, but the object not rotate correctly

update:function{

  var mousePos = me.input.globalToLocal(me.input.pointer.clientX,me.input.pointer.clientY);
  var angle = this.angleToPoint(new me.Vector2d(mousePos.x, mousePos.y));

  this.renderable.currentTransform.rotate(angle - this.PrevAngle);
  this.PrevAngle = angle; 
} 

Thanks

Share this post


Link to post
Share on other sites

me.pointer.pointer.pos is already a Vector object, so you should be able to directly use it with the angle function, with something like  “this.renderable.currentTransform.rotate(this.pos.angle(me.input.pointer.pos);”

 

which version of melonJS are u using ? Older (5.x), required the renderable.autoTransform to be manually set to true.

Share this post


Link to post
Share on other sites
On 12/27/2018 at 3:55 PM, obiot said:

me.pointer.pointer.pos is already a Vector object, so you should be able to directly use it with the angle function, with something like  “this.renderable.currentTransform.rotate(this.pos.angle(me.input.pointer.pos);

 

which version of melonJS are u using ? Older (5.x), required the renderable.autoTransform to be manually set to true.

Im using 6.1.0,

I tried your code but still not rotate correctly

Share this post


Link to post
Share on other sites

There is really nothing more to it, it’s a pretty simple and straighforeward function, and if it rotates in the wrong direction just negate the angle.

I wish i could provide you a more detailed answer but on this year end i’m traveling and do not have my laptop. So unless someone else can provide a better answer you will have to experiment a bit by yourself to find the solution you need.

 

Happy New Year !

Share this post


Link to post
Share on other sites
1 hour ago, obiot said:

considering the result in wall to wall, I supposed you managed to fix it ?

good mini-game by the way, I had fun playing it and almost did 100 points :)

yes i managed to fix it, i'm using math.atan2 to calculate angle,

btw thanks for playing my game

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.