Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | HarryCourt | |
Old Version | Published before Godot 3 was released. |
I have this teleport node that the player will collide with, that will hopefully make change the position of the player. But everytime I run the game, when it collides with the node, it crashes! Can someone help me please?
extends KinematicBody2D
#const GRAVITY = 200.0
const WALK_SPEED = 1200
var MyPos = self.get_pos()
#var teleportTile = get_node("Teleport1").get("teleportPos") The code where everything changed...
var velocity = Vector2()
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
var motion = velocity * delta
move(motion)
if is_colliding():
var collider = get_collider()
if collider.is_in_group("Tile"):
get_node("SamplePlayer").play("TileOn2")
collider.queue_free()
elif collider.is_in_group("Teleporter"):
set_global_pos(Vector2(get_node("Teleport1").get("teleportPos")))
get_node("SamplePlayer").play("Finish")
collider.queue_free()
velocity.x += delta #* GRAVITY
velocity.y += delta #* GRAVITY
if (Input.is_action_pressed("ui_left")):
velocity.x = -WALK_SPEED
elif (Input.is_action_pressed("ui_right")):
velocity.x = WALK_SPEED
elif (Input.is_action_pressed("ui_down")):
velocity.y = WALK_SPEED
elif (Input.is_action_pressed("ui_up")):
velocity.y = -WALK_SPEED
else:
velocity.x = 0
velocity.y = 0