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
asked Jul 7 in Engine by INKnight (37 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)
answered Jul 8 by INKnight (37 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.