Chpsterz Posted April 4, 2021 Share Posted April 4, 2021 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 comment Share on other sites More sharing options...
Exca Posted April 6, 2021 Share Posted April 6, 2021 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 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.