Answers for "godot invalid get index "global_position" (on base:"Nil")"

Go
0

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
Posted by: Guest on February-17-2020

Code answers related to "godot invalid get index "global_position" (on base:"Nil")"

Browse Popular Code Answers by Language