Search code examples
javalibgdxrotationspritepoint

Why is the rotation point of a sprite using setOrigin is not set to the middle of the sprite?


I wanted to be able to rotate my cursor around my sprite and have it rotate relative to my mouse's position

I have used setOrigin(x,y) to set the pivot point to the center of the sprite

It worked to a degree, but its not exactly what i'm looking for

This was the end result:

https://gfycat.com/gifs/detail/CrazyPleasedIberianlynx

For simplicity and because I don't know what it's officially called, I'll just call the rotation on the center of the sprite the "pseudo" pivot point,

and the point in which the sprite rotates, the one on the grass most of the time, the "true" pivot point

I want to either set the sprite to move the "true" pivot point or to move the "true" pivot point to the sprite

I have looked around for the solution but I couldn't find the answers i'm looking for

Thank you in advance


Solution

  • I think i figured it out.

    In regards to the mouseCoordinates, It was part of the problem.

    Apparently i needed to unproject the mouse from the camera.

    I used gdx.input.getX() and gdx.input.getY() for the projected mouseCoordinates.

    As for the matter of centering the "True" pivot point to the sprite, i had to change the spriteCoordinate value of the function i made.

    Here is the function in question pastebin.com/06zJ4DtS

    copied from the comment i made.