I'm am programing a simple game and I need a character/sprite to face the cursor at all times, is this possible with raylib and c++? Do I need any other tools?
I tried treating the image as a Vector2d
I'm am programing a simple game and I need a character/sprite to face the cursor at all times, is this possible with raylib and c++? Do I need any other tools?
I tried treating the image as a Vector2d
The atan2
function in cmath returns an angle pointing towards the x and y position in radians, here's an example using atan2
:
float x = GetMouseX() - position.x,
y = GetMouseY() - position.y;
float rotation = atan2(x, y) * -57.29578f; // Multiplies the angle by -57.295 to convert to degrees
DrawTexturePro(Image, Rectangle{0, 0, (float)Image.width, (float)Image.height},
{ position.x, position.y, ImgWidth, ImgHeight },
{ ImgHeight/2, ImgWidth/2 }, rotation+180, RAYWHITE);