0

I am trying to teleport my player node(kinematicbody2d) when it hits my finish node (area2d) from the side of the Finish node
BTW I'm using godot 3

What I tried:
Change the location using get_node("player").set_pos and get_node("player").location

code:

extends Area2D

func _on_Finish12_body_entered(body):
        if body.get_name() == "player":
                print("%s touched the finish on level %s" % [body.get_name(), get_tree().get_current_scene().get_name()])
                get_node("player").position = Vector2(1504, 1896)
                pass

So what I need:
The playing being teleported to 1504, 1896

2 Answers2

0

There's a lot of unknowns here that can be the problem

  • Is the player's location updated in other parts of the code? and if so, could it be possible you did move to 1504, 1896 but then immediately get clobbered by said code?
  • What is the current behavior when you apply the new position? Does your player move at all? Does it go somewhere unintended?
  • Does your print statement execute?
  • Have you tried using move_and_slide/move_and_collide for the kinematicBody to check for collision?

Just a few ideas on how to go about figuring it out.

0

This is what works with Area and KinematicBody (i.e. 3D):

extends Area
func _on_Area_body_entered(body):
    body.look_at_from_position(spawn, Vector3(0,0,0),  Vector3(0,0,0))

with spawn being an empty spatial to define the point in space to teleport to.

dirkk0
  • 2,460
  • 28
  • 34