sistemlogikadigital Posted December 27, 2018 Share Posted December 27, 2018 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 Quote Link to comment Share on other sites More sharing options...
obiot Posted December 27, 2018 Share Posted December 27, 2018 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. Quote Link to comment Share on other sites More sharing options...
sistemlogikadigital Posted December 28, 2018 Author Share Posted December 28, 2018 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 Quote Link to comment Share on other sites More sharing options...
obiot Posted December 31, 2018 Share Posted December 31, 2018 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 ! Quote Link to comment Share on other sites More sharing options...
obiot Posted January 5, 2019 Share Posted January 5, 2019 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 Quote Link to comment Share on other sites More sharing options...
sistemlogikadigital Posted January 5, 2019 Author Share Posted January 5, 2019 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.