Godot Version
4.X
Question
basically, im using
func _physics_process(delta: float) → void:
var input = Input.get_vector(“left”, “right”, “up”, “down”)
velocity = input * speed
velocity_rotation()
move_and_slide()
and i’m rotating the sprite using :
func velocity_rotation():
if velocity.x != 0:
rotation = lerp_angle(rotation,velocity.x + pi,0.2)
else:
rotation = 0
and it works, but because get_vector normalizes the vector, the rotation code gets messed up. so I want to find a way to de-normalize the vector
No, de-normalizing the vector makes no sense, to me at least. I think you need to change your rotation function. But I can only guess at the behaviour you are trying to achieve.
Something like this perhaps?
func velocity_rotation(input: Vector2):
if input != Vector2.ZERO:
var target_angle = input.angle()
rotation = lerp_angle(rotation, target_angle, 0.2)
else:
rotation = lerp_angle(rotation, 0, 0.2)
This just calculates the angle of the input vector, then lerps the rotation to it, or back to 0. You may need to modify it for your particular case use. Hope that helps.
1 Like