Rotate RigidBody2D to mouse without breaking collisions

Godot Version



I’m trying to rotate my player (RigidBody2D) towards my mouse without breaking collisions. My previous attempt was this, but the player just spins around super fast.

func _integrate_forces(state):
	var rot = get_angle_to(get_local_mouse_position()) # Get angle to mouse
	var form = state.get_transform() # Get transform from current state
	form = form.rotated(rot - form.get_rotation()) # Get difference between current rotation and aim rotation and add it to current rotation
	state.set_transform(form) # Apply changes

	# ...

How can i make it work without breaking collisions?

You could just use:

This way, your player should rotate towards the mouse position.

1 Like

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