This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm having this problem:
I have 2 players, when a player is dead, the collision layer/mask bit for colliding with other players is disabled. After some time, the player respawns and teleports to another place. But when a player is inside the dead player collision, it simply warps to the nearest point outside the collision.

Red player warps to the nearest point outside the blue player collision
Note: my code firstly teleports the player, them enable the collision bits.

yield($Respawn, "timeout")
position = get_parent().get_respawn_positions()[randi()%4].position
set_collision_layer_bit(0, true)
set_collision_mask_bit(0, true)
is_dead = false
in Engine by (41 points)

(Wild guess)
Not sure if this is a good/clean solution, but maybe you should try to set the collision-layer (and mask?) 1 frame later.

Yeah. I think everything is happening so fast and at the same frame. Maybe deferring the call or wait for the idle frame? Or even use another yield "timeout"? I'm curious about this too.

if i understand the physics-engine correctly, there is no update in the same frame after you change the position.
I also cannot find a way to recalculate the physics after you change the position manually.
If someone knows a clean way, i would be very interested!

1 Answer

+2 votes
Best answer

So, I tried whiteshampoo and arthurZ solution above by waiting a frame after the "warp" before setting the collision bits, and worked like a charm, thank you guys!

position = get_parent().get_respawn_positions()[randi()%4].position
yield(get_tree(), "idle_frame")
set_collision_layer_bit(0, true)
set_collision_mask_bit(0, true)
by (41 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 Frequently asked questions and 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 [email protected] with your username.