Invalid get index 'transform' (on base 'bool')

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By young.fernand

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

Where’s target declared tho?

Dlean Jeans | 2019-11-28 05:06

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.

Saitodepaula | 2019-12-05 14:06