+1 vote

I have created a spacial node called Troll, which has two children: Troll and Sight. Both of them are areas. This is my code for the spacial Troll:

extends Spatial

var velocity = Vector3(0, 0, 0)
var saw = false
var player = null
const SPEED = 2

func _process(delta):
    if saw == true:
        look_at_from_position(player.position, player, Vector3(0, 1, 0))
        velocity.y += SPEED

func _on_Troll_body_entered(body):
    player = body
    saw = true

func _on_Troll_body_exited(body):
    player = null
    saw = false

This is the error:
Invalid type in function 'lookatfrom_position; in base "Spatial (MainTroll.gd)'. Cannot convert argument 2 from Objects to Vector3.

"MainTroll.gd" is the script (shown above)

Do you know what's wrong? Sorry, I'm new to this function.

in Engine by (32 points)

1 Answer

0 votes

player is an object not a Vector3. You can only use Vector3's as arguments for this function. Also for the player.position part, you actually want to use player.translation as player.postition is for Node2D not Spatial. Here's some documentation that should help.

by (144 points)

Then what should the Vector3 Target be?

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 Frequently asked questions and 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.