Topic was automatically imported from the old Question2Answer platform.
Asked By
Shazelz
I am trying to get the transform of an object so that I can use the look_at function so that the kinematic body is looking at it the only problem is that I am having trouble getting the transform of the player what I was trying to do was
to get the transform but that does not work as I get the
Invalid get index 'global_transform' (on base: 'Nil').
I would just like to know if there is any way that I can ger a Vector3 for the Look_at() so that the enemy will look at the player
(This is also multiplayer if that is of any consequence)
I need to get the origin for the look_at() but nothing seems to be working
(possible players is just a array full of the players)
Shazelz | 2021-03-25 20:40
Sorry to have been so vague before. I meant how is your code setup that captures the collision. Because usually you’d do
If $Raycast.is_colliding():
target_player = $Raycast.get_collider()
if target_player.is_in_group("player"):
look_at(target_player.global_transform.origin, Vector2.UP)
But without knowing what your “ray_collide” var actually is/does then that’s as far as my olive branch can extend because all of your code looks legit on the surface
In your last example change Vector3(0, 0, 0) to Vector3.UP