+1 vote

Hello,

So basically I need functionality as it is used in many 2D games.

I'd like to create an location/area that my character enters and then gets "beamed" into another spawn location/area.
This can also be useful for scene transitions in games where you can go back and forth.

Thanks a lot guys
Oliver

P.S. Excuse me if I feel lazy, but I'm just starting out with GD Script / Python.

in Engine by (43 points)

2 Answers

+1 vote
Best answer

You could place a Node2D whose only purpose is to be used as position to spawn a player. To create the teleport entrance, use an Area2D node and connect its signal to a function that will move the player to the teleport destination (the Node2D's position).

by (7,882 points)
selected by

Also, a Position2D might be preferable to a pure Node2D, as it has a crosshair you can use to place it nicely and accurately but which won't be visible in the game.

0 votes

In our game we use Position2d node as spawnposition.

For spawning enemy randomly on defined points we do it like this

randomize()
spawnPoints = map.get_node("spawnPoints").get_children()

for enemy in enemys:
    var spawnIndex = randi() % spawnPoints.size()
    var spawnPoint = spawnPoints[spawnIndex]
    spawnPoints.remove(spawnIndex)
    var pos = spawnPoint.get_global_pos()
    get_node("game/objects").add_child(enemy)
    enemy.set_global_pos(pos)
by (677 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories