So, I'm trying to make my enemy look at my player.
I was using the look_at()
function. This worked. The only problem with it is, that the enemy turned instantly, and not gradually.
I then found this reddit post. There i found the following code snippet:
func turn_face(target, delta):
var rotation_speed = 3
var target_pos = target.global_transform.origin
var pos = global_transform.origin
target_pos.y = pos.y
var origin_rot = rotation
look_at(target_pos, Vector3(0,1,0))
var target_rot = rotation
var rot_length = target_rot - origin_rot
var rot_step = rot_length * rotation_speed * delta
rotation = origin_rot + rot_step
I was able to make this work. But there is one problem.
It does not handle any wrapping. Sometimes the enemy just makes a quick 360. and well I don't want that he does that.
I then looked a little bit further and found this question. Yes I got this working as well. But I have 2 problems with it.
First, this method wants an object and then gets it's position. But I can't always give the function an Object/Target. I need to give it a position.
Second, sometimes the enemy looks very weird when turning. Like squeezed or something.
But when using this, the enemy does turn around perfectly and isn't doing any 360's.
What I'd like to know is, how I could use the first example (not the tweening thing) with a way to wrap around. I heard I need to use something like basis or quat? If so, I have no clue on how to use those.
Or on how to use the tweening method, but without that squeezing and without giving an object but rather giving straight a position.
I hope it's clear what I'm asking for.
And sorry if my english isn't so good, I'm still learning!
Thank you all for the help, and I hope you all are doing good with that quarantine thing going on.