Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RigidBody2D cannot rotate after CollisionShape2D is disabled #41024

Open
Tracked by #45334
lukepass opened this issue Aug 4, 2020 · 3 comments
Open
Tracked by #45334

RigidBody2D cannot rotate after CollisionShape2D is disabled #41024

lukepass opened this issue Aug 4, 2020 · 3 comments

Comments

@lukepass
Copy link

lukepass commented Aug 4, 2020

Godot version:
3.2.2.stable.official

OS/device including version:
Kubuntu 18.04

Issue description:
As described in this issue:

#30551

After a RigidBody2D disables its CollisionShape2D, it cannot be rotated until the shape is re-enabled.

Steps to reproduce:
This is my player:

image

This is the change_state method of my player (you can see that INIT and INVULNERABLE disable collision):

func change_state(new_state):
	match new_state:
		INIT:
			$CollisionShape2D.set_deferred("disabled", true)
			$Sprite.modulate.a = 0.5
		ALIVE:
			$CollisionShape2D.set_deferred("disabled", false)
			$Sprite.modulate.a = 1.0
		INVULNERABLE:
			$CollisionShape2D.set_deferred("disabled", true)
			$Sprite.modulate.a = 0.5
			$InvulnerabilityTimer.start()
		DEAD:
			$CollisionShape2D.set_deferred("disabled", true)
			$Sprite.hide()
			linear_velocity = Vector2()
			angular_velocity = 0
			emit_signal("dead")
	state = new_state

And this is the method used to rotate the player:

func _integrate_forces(physics_state):
	set_applied_force(thrust.rotated(rotation))
	set_applied_torque(spin_power * rotation_dir) # this line is not working when shape is disabled
	var state_transform = physics_state.get_transform()
	if state == INIT:
		state_transform = Transform2D(0, screensize/2)
	if state_transform.origin.x > screensize.x + radius:
		state_transform.origin.x = 0 - radius
	if state_transform.origin.y > screensize.y + radius:
		state_transform.origin.y = 0 - radius
	if state_transform.origin.x < 0 - radius:
		state_transform.origin.x = screensize.x + radius
	if state_transform.origin.y < 0 - radius:
		state_transform.origin.y = screensize.y + radius
	physics_state.set_transform(state_transform)

When the player is in the INVULNERABLE state it doesn't rotate. Please note that spin_power * rotation_dir is correctly set to a correct value even in that state.

Minimal reproduction project:

https://bitbucket.org/lukepass/space-rocks/src/master/

Here is the zip: https://bitbucket.org/lukepass/space-rocks/get/7fad1b35ac35.zip

Please the the invulnerability timer to 10 seconds in the Player scene then run the game. Hit a rock and try to turn.

Thanks!

@Rubonnek
Copy link
Member

Rubonnek commented Aug 5, 2020

I'm able to reproduce this issue with 23b553b

@Rubonnek
Copy link
Member

Rubonnek commented Aug 5, 2020

I also got some errors on the console after running your code, but it's a matter of deferring spawn_rock on _on_Rock_exploded:

call_deferred("spawn_rock", size - 1, new_position, new_velocity)

@lukepass
Copy link
Author

lukepass commented Aug 5, 2020

Thanks for the additional correction! As a side topic, do you know where can I find more info about why sometimes is necessary to use call_deferrend when calling methods in process?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants