Why does my code rotate my character wrong?

Godot Version

v4.2.1.stable.mono.official [b09f793f5]

Question

Why does this code

	var inputDir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	var direction = transform.basis * Vector3(inputDir.x, 0, inputDir.y).normalized()
	var sum = direction * speed

	if inputDir.length_squared() > 0:
		rotation.y = inputDir.angle()

rotate my character in the wrong direction?

left is up
up is left
right is down
down is right

I checked my input map and they are right? I have no clue

1 Like

In Godot vector work like this:

sorry if it looks bad I made it in paint

you did it correctly here but not with the rotation

Ok, Do you know how to fix it?

you can try this

	if inputDir.length_squared() > 0:
		rotation.y = rad_to_deg((inputDir.angle()))

I actually figured it out. For some reason the code for the rotation var is:
var rotation_dir = Input.get_vector("ui_up", "ui_down", "ui_left", "ui_right")
and then later rotation.y = rotation_dir.angle()

1 Like

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