how to rotate towards direction godot code example

Example: godot 3d slowly rotate towards object

# Slowly rotate towards object in 3D space
func turn_face(target, rotationSpeed, delta):
	var global_pos = global_transform.origin
	var wtransform = global_transform.looking_at(Vector3(target.x,global_pos.y,target.z),Vector3(0,1,0))
	var wrotation = Quat(global_transform.basis).slerp(Quat(wtransform.basis), rotationSpeed*delta)

	global_transform = Transform(Basis(wrotation), global_transform.origin)

Tags:

Misc Example