How do you rotate a sprite based on mouse position?
Hi Guys,
I have created a sprite that rotates to face the mouse position, and have made a long’ish level. When I place it on the left side of the level everything works as it should, but when it’s on the right the rotation doesn’t work and just seems to gets limited to a small range of rotation.
To do this I used an update loop by adding a timer that is set to every 0.2 seconds. I then placed within it a 'change Attribute' and set self.rotation to equal vectorToAngle( self.position.X - game.Mouse.Position.X , self.position.Y - game.Mouse.Position.Y ).
Does anybody know what is causing this problem?
Cheers,
Guardian
I have created a sprite that rotates to face the mouse position, and have made a long’ish level. When I place it on the left side of the level everything works as it should, but when it’s on the right the rotation doesn’t work and just seems to gets limited to a small range of rotation.
To do this I used an update loop by adding a timer that is set to every 0.2 seconds. I then placed within it a 'change Attribute' and set self.rotation to equal vectorToAngle( self.position.X - game.Mouse.Position.X , self.position.Y - game.Mouse.Position.Y ).
Does anybody know what is causing this problem?
Cheers,
Guardian
Comments
You need to add an offset for the camera because you made your scene bigger. Also you can just use a constrain attribute instead of a timer with change attribute if you wanted.
Cheers
P.S There is a reason I didn't use attribute constrain. I need to do something a lot more complicated but I narrowed down the issue to the above to make it easier repeat and solve.