#How to create a smooth lookat() function

1 messages · Page 1 of 1 (latest)

deep rose
#

anyone know how to get a smooth lookat() function? I am making a tank game, and I do not how to make the AI's turret rotate at a constant speed towards the player without it essentially snapping to it.

foggy root
#

I have turrets in my game which needed to similarly turn bit by bit.

#

func rotate_slow_turret_tops(delta: float): var _targ_point = cur_target.target_point.global_position var _direction = turret_top.global_position.direction_to(_targ_point) var _new_rotation = turret_top.global_transform.looking_at(_targ_point) turret_top.global_transform = (turret_top.global_transform. interpolate_with(_new_rotation, turn_weight)) turn_weight = clamp(turn_weight + 0.0001, 0.0, 1.0)

Intended to be called in the _process func

#

the trick is getting the new rotation with the looking_at func which returns a transform looking at the target. Then combining that with the interpolate_with func which takes the current transform and blends it with the new one.