godot invalid get index "global_position" (on base:"Nil")
var speed: = Vector2(30.0 , 30.0)
var direction: = Vector2(1,0)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var velocity = speed * direction
velocity = move_and_slide(velocity)
func _on_Area2D_body_entered(body: KinematicBody2D) -> void:
direction.x = - direction.x
if body.global_position.y > get_node("CollisionShape2D").global_position.y:
direction.y = 1
else:
direction.y = -1
func _on_collision_body_entered(body: RigidBody2D) -> void:
if body.global_position.y > get_node("CollisionShape2D").global_position.y:
direction.y = 1
else:
direction.y = -1