0 votes

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.

Godot version v.3.3.3
in Engine by (12 points)

2 Answers

0 votes

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 ?

by (2,468 points)

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_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

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

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 will try that. Thanks!

0 votes

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).

by (14 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.