Sprite change according to direction

Godot Version

v4.5.1-stable

Question

Hello! I'm currently remaking my gamemaker game in godot(GM is just not as capable) and I've encountered a major roadblock. I have a sprite sheet with 36 frames that represents every direction the player could face towards (fake3D). previously in GM I used the following method to change it according to where is the player heading: direction = point_direction(x,y, mouse_x, mouse_y) facing = round(direction*36/360) // math is: round(direction*framecount/360) image_index = facing My problem is, that there is no such function in Godot that could replace point_direction. Is there a way to achieve the same result? I have tried position.direction_to() but it failed. I'm also using $Sprite2D.frame = 0 to change the frame

Vector2::angle_to_point()

Here’s the whole thing:

func get_angle_zone(origin: Vector2, point: Vector2, steps: int) -> int:
	var angle := origin.angle_to_point(point)
	angle += TAU if angle < 0 else 0
	return wrapi(round(angle * steps / TAU), 0, steps)
2 Likes

Wow, thank you, I tought there would be an easier way

1 Like