Chpsterz 0 Posted April 4 Report Share Posted April 4 Hey guys so I am creating a game with PixiJS and I need help with trying to make the sprite look in the direction of the mouse pointer. Can someone help me? Quote Link to post Share on other sites
Exca 124 Posted April 6 Report Share Posted April 6 Calculate the angle between mouse and the object and then set that to your objects rotation.: const mouse = renderer.plugin.interaction.mouse; const dx = mouse.x - object.x; const dy = mouse.y - object.y; object.rotation = Math.atan2( dy, dx); Written from memory without testing so not 100% sure everything is correct. But that's the basic idea. Also depending on what your objects "forward" direction is, you might need to add an offset to atan2 result. Quote Link to post Share on other sites
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.