0 votes

I have a code on 3D.

extends KinematicBody
export (float) var rotation_speed
export (int) var detect_radius

func _ready():
    $DetectArea/CollisionShape2.shape.radius = detect_radius
func _process(delta):
    if target:
        **var target_dir = (target.transform.origin - transform.origin).normalized()**
        var current_dir = Vector2(1,0).rotated($Cube005.global_rotation)
        $Cube005.global_rotation = current_dir.linear_interpolate(target_dir, rotation_speed * delta).angle()

func _on_DetectArea_body_entered(body):
    if body.name == "watu":
        target = body
    pass

func _on_DetectArea_body_exited(body):
    if body == target:
        target = null
    pass

every I trying to play scene show message "Invalid get index 'transform' (on base 'bool')". i don't know how to solving this

in Engine by (23 points)

Where's target declared tho?

Where is your script attached? On a kinematic body, a spatial node that is the parent of everything else, on a mesh...

Try adding this two lines in the func _ready():

print(target.transform.origin)
print(transform.origin)

to see what is returned, and if it's consistent to what you have in the 3D space.

Please log in or register to answer this question.

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.