Hey. I am moving and rotating my Player with the following lines:

``````func physics_process(delta):
player.motion = player.position.direction_to(player.get_global_mouse_position()) * 600

player.look_at(player.get_global_mouse_position())
``````

The look_at method makes it turn almost instantly. I want to make that more smooth. Can anyone help me with this please? (Maybe with a Tween?)

Thanks.

Edit: If you're wondering why I am using a reference to the player and why I don't use physicsprocess(delta). This script is from a subclass of a State machine which controls Player movement. The actual physicsprocess method is in the Base Class.

in Engine

I am currently looking for the same thing.

After searching the web this code was pointed to me as a possible solution, but I am not very familiar with tweens. This code is also really fast and I can't seem to make it turn slower.

Hope it helps anyway.

extends Node2D

func _process(delta):

``````# target to look at
var target = get_global_mouse_position()

# initial and final x-vector of basis
var initial_transform_x = self.transform.x
var final_transform_x = (target - self.global_position).normalized()

# interpolate
TweenNode.interpolate_method(self, '_set_rotation', initial_transform_x, final_transform_x, 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT)
TweenNode.start()
``````

apply rotation

func setrotation(new_transform):

``````# apply tweened x-vector of basis
self.transform.x = new_transform

# make x and y orthogonal and normalized
self.transform = self.transform.orthonormalized()
``````
by (29 points)
+1 vote

lookat is not the function you need, you need lookingat, which creates a new transform.
i basically create a new transform that look at the target, and then i used lerp to interpolate the x,y,z basis of the camera transform with the one of the created transform

``````func _process(delta):  #inside camera process
var T=global_transform.looking_at(target.global_transform.origin, Vector3(0,1,0))
global_transform.basis.y=lerp(global_transform.basis.y, T.basis.y, delta*camera_speed)
global_transform.basis.x=lerp(global_transform.basis.x, T.basis.x, delta*camera_speed)
global_transform.basis.z=lerp(global_transform.basis.z, T.basis.z, delta*camera_speed)
``````
by (1,455 points)
``````var weight = 0.1