0 votes

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

target_player = ray_collide

target_player.global_transform.origin

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)

Godot version 3.2.3
in Engine by (72 points)
edited by

1 Answer

+1 vote

Your target_player var is not properly set.
So ensure that its nodepath resolves correctly

by (4,972 points)

I set it as the collision of the ray cast which only collides with the player and only tries to find the transform if the ray cast has a collision

Odd. Its obviously returning null. How is the code for your Raycast setup?

    if ray_collide != null:
       if ray_collide_.is_in_group("player") == true:
          target_player = ray_collide

and the ray cast is returning the kinematic body the only thing is when I try to get the translation of it for the look_at() it doesn't work

Another problem has also come up with this

    look_at(possible_players[0].get_translation(), Vector3(0, 0, 0))

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)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.