Topic was automatically imported from the old Question2Answer platform.
Asked By
vtlx
After detecting collision with another RigidBody2D I disable CollisionShape2D with:
$CollisionShape2D.set_deffered(“disabled”, true)
// for some reason simple $CollisionShape2D.disabled = true - disn’t work as Player still collided.
Then I start timer and on Timer’s timeout signal I enable it back again like this:
$CollisionShape2D.disabled = false
In that short period of time while the Timer is running my Player doesn’t rotate - only flies forward, after that everything seems to be working fine and I can’t figure out what can cause such an issue.
Must be something with your movement code. Do you have any rotation scripted, or is it only torque dependent ? Is there nothing in debugger console at the moment of collision ?
Hi, Inces
Thanks for the answer. No, there’s nothing in the console when the bodies collide. The problem happens when the player hits another RigidBody2D node, then for 2 seconds Player’s CollisionShape2D gets disabled and for those 2 seconds the body is unable to rotate (and there’s still no bugs shown) it only goes straight forward.
The Player’s movement script is pretty usual:
func _integrate_forces(physics_state):
set_applied_force(thrust.rotated(rotation))
set_applied_torque(spin_power * rotation_dir)
var xform = physics_state.get_transform()
if xform.origin.x > screensize.x + round(players_radius.x/2):
xform.origin.x = 0
if xform.origin.x < 0 - round(players_radius.x/2):
xform.origin.x = screensize.x
if xform.origin.y > screensize.y + round(players_radius.y/2):
xform.origin.y = 0
if xform.origin.y < 0 - round(players_radius.y/2):
xform.origin.y = screensize.y
physics_state.set_transform(xform)
I guess this section set_applied_force(thrust.rotated(rotation)) doesn’t work properly with the CollisionShape disabled. Is rotation depends on the Shape being enabled…hmm
vtlx | 2021-10-01 08:03
Yeah, it is weird. I don’t know what do You want to happen in game, but maybe disabling shape is overdoing it ? Can’t You change collision layer instead ? Or collision monitoring ?
I was going through the same issue, but I noticed that the collision shape is part of the physics calculations on the body; even if you modify the size of the collision shape, the forces applied vary.
To work this around, set both collision layer and collision mask to a number you have no other entities assigned to (for example: 32 and 32).