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

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

  • Recently Browsing   0 members

    No registered users viewing this page.