How do you rotate a sprite based on mouse position?

GuardianGuardian Member Posts: 54
edited March 2012 in Working with GS (Mac)
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

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Please dont make multiple threads on the same thing, expecially when your question was answer in your other thread. http://forums.gamesalad.com/discussion/41210/rotation-flip-based-on-sprite-position#Item_2

    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
  • GuardianGuardian Member Posts: 54
    It wasn't answered...
  • GuardianGuardian Member Posts: 54
    Thanks, but the camera is also controlled by the actor. So where ever the actor is the camera follows and I'm getting the same issue.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Dont mind the first part of the second paragraph. I didnt mean to post that here, and it wouldnt let me edit my comment for a while. That shouldnt effect the rotation. Im gonna look into this now for you.
  • GuardianGuardian Member Posts: 54
    Thank you. That would be very helpful.

    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.

Sign In or Register to comment.