How to rotate around player based on mouse position?

Godot Version

4.3

Question

I’m trying to make it so that the player can rotate a shield around them. I want the shield to angle towards wherever the mouse is relative to the player. I have the following functions that attempt to do this:

In the player script:

		var mouse_pos = get_global_mouse_position()
		return (mouse_pos - global_position).normalized()

In the class script with the shield:
func _physics_process(delta) → void:

	if shield_wall_is_up:
		var direction = player.get_aim_direction()
		var target_angle = direction.angle()
		$ShieldWall.rotation = lerp_angle(rotation, target_angle, rotation_speed * delta)

The problem I am having, is that when I set the rotation speed to a number lower than 25, it barely moves no matter where I move the mouse. If I set that number above 25, it will move almost instantly, but won’t move behind the player.

The desired behavior is for it to be able to go 360 degrees around the player wherever they are aiming, but also not instantly move, and have a “travel speed”.

Any thoughts on what’s happening here?

Never mind, I’m an idiot. I was using the character’s position in the lerp instead of the shield’s position. It works now…

1 Like

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