Function "look_at()" not found in base self
Asked Answered
H

8

0

Hello, I'm new to this forum! I'm using Godot's version 4.1.1 Stable.

I'm having difficulties with the "look_at" and "look_at_from_position" function.

I've seen these functions being used in several tutorials and websites, but the compiler is displaying the following message in every attempt I made: Function "look_at()" not found in base self.

Does anyone know if this function has been disabled and/or replaced in this latest version? What am I doing wrong?


Thanks in advance for the answers!

Hanhhank answered 20/8, 2023 at 16:11 Comment(0)
C
0

Node does not have a look_at function. That wouldn't make any sense since Node doesn't have a position either. You will want to use either Node2D or Node3D.

Canonicals answered 20/8, 2023 at 16:20 Comment(0)
G
0

Canonicals Marking your reply as the best answer

Gaggle answered 20/8, 2023 at 17:1 Comment(0)
H
0

Canonicals I am suffering up with this simple Node.
After this adjustment, I have this error here in "global_transform.origin".

My object is to make this 3D object look at the Camera. Just that.


Hanhhank answered 20/8, 2023 at 17:11 Comment(0)
C
0

target is null. Something about your node path is wrong.

Canonicals answered 20/8, 2023 at 17:27 Comment(0)
J
0

Add this and post the output:

func _ready():
        print_tree()

Reference: https://docs.godotengine.org/en/4.1/classes/class_node.html#class-node-method-print-tree

Jeter answered 20/8, 2023 at 17:34 Comment(0)
H
0

I put the code in the right place: 'player_ratinho/camera_mount/Camera3D'

The structure of the scenes are separate. Camera3D is inside the Player scene and the Player scene is inside the Game Scene;

And the object that will look at the camera is within the scene of an Item, which is within the scene of a scenario and this scenario is within the Game scene;


In my view it is well divided... But now to get the right path is what complicated it, right?

Hanhhank answered 20/8, 2023 at 17:50 Comment(0)
J
0

If the script you posted is attached to the node point_look_at, then the correct path would be:
@onready var target = $"/root/game_rats/player_ratinho/camera_mount/Camera3D"

There might be another problem. The variable target is initialized when the node point_look_at is "ready". But the node Camera3D might not be in the scene tree yet.

Jeter answered 20/8, 2023 at 20:40 Comment(0)
H
0

Jeter This change of the Target path solved my problem! Thank you for the patience!!! =D

@onready var target = $"/root/game_rats/player_ratinho/camera_mount/Camera3D"

Then I just need to change the rotation of the object and I got the expected result!

Hanhhank answered 21/8, 2023 at 2:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.