Topdown character look_at works with 90 degree offset

Godot Version

4.3

Question

Hi, i am trying to make a top down shooter game. While i want to rotate character with mouse so i used look_at(get_global_mouse_position()) but there is always 90 degree difference between character direction and mouse as following gif:
move_movement
my code:

extends CharacterBody2D

@export var speed = 400

func get_input():
	look_at(get_global_mouse_position())
	velocity = transform.x * Input.get_axis("down", "up") * speed

func _physics_process(delta):
	get_input()
	move_and_slide()

scene tree:
image

thanks.

Move Sprite to be a child of CharacterBody2D instead of CollisionShape2D

After that, confirm that Test, CharacterBody2D or the Sprite2D don’t have any rotation applied.

@esaddag I have similar problem with raycast.look_at. Did you find a solution? Can you share?

few hours later: I gues not =) No problem, some people helped me to solve my problem. You can probably solve yours just by changing Sprite rotation in the inspector. Good luck :wave:

1 Like

I gave up once and just rotated the sprite image in gimp :laughing:

Hi.
First of all, move your Sprite2D to be a child of the CharacterBody2D, not as a child of the collision shape. Like this:

image

Second, I replicated your scene. The look_at function uses as “forward” the vector [1, 0] (basically the red arrow you see in the picture over the character. That direction is given by the CharacterBody2D node.

The solution is simple, rotate your sprite 90 degrees.

Here’s the result.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.