![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | PhilipCz |
I’m trying to make a 2D top-down game. I’ve tried to figure out a way to have my player “teleport” to a new scene but I simply can not figure out how to do it. How would I best do this?
My Player code:
extends KinematicBody2D
export var MOTION_SPEED = 140
var Level = 1
var RayNode
func _ready():
set_physics_process(true)
RayNode = get_node("RayCast2D")
func _physics_process(delta):
var motion = Vector2()
MOTION_SPEED = 140
#Input+Motion
if (Input.is_action_pressed("ui_up")):
motion += Vector2(0,-1)
RayNode.set_rotation_degrees(180)
if (Input.is_action_pressed("ui_down")):
motion += Vector2(0,1)
RayNode.set_rotation_degrees(0)
if (Input.is_action_pressed("ui_left")):
motion += Vector2(-1,0)
RayNode.set_rotation_degrees(-90)
if (Input.is_action_pressed("ui_right")):
motion += Vector2(1,0)
RayNode.set_rotation_degrees(90)
#Sprint
if (Input.is_action_pressed("ui_Sprint")):
MOTION_SPEED = 200
#Apply Motion
motion = motion.normalized()*MOTION_SPEED*delta
move_and_collide(motion)