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

Crash when activating/disabling CollisionShape2D in various cases #11695

Closed
Boothand opened this issue Sep 29, 2017 · 6 comments
Closed

Crash when activating/disabling CollisionShape2D in various cases #11695

Boothand opened this issue Sep 29, 2017 · 6 comments

Comments

@Boothand
Copy link

Operating system or device, Godot version, GPU Model and driver (if graphics related):
Godot 3.0, recent Calinou build from 27/09

Issue description:

Using move_and_slide on a KinematicBody2D in combination with disabling a CollisionShape2D and enabling another crashes when the KinematicBody2D hits the a surface.

Steps to reproduce:

  1. Put KinematicBody2D in a scene, give it two CollisionShape2D capsule shapes.
  2. Use move_and_slide to move it down towards a static collider.
  3. Click a button to disable the first collider and activate the other. It crashes when there is collision.

Link to minimal example project:

Use button 'space' to activate/disable the colliders.
Crash with colliders.zip

@groud groud added this to the 3.0 milestone Sep 29, 2017
@Boothand
Copy link
Author

Would be interested to know workarounds. Needed for stuff like having a smaller collision box when crouched.

@saturnian-tides
Copy link

Can you live with using a single collider? As a workaround you might try simply set the extents of your collider to match what you want it to be on crouch, and then revert the extents once you leave the crouch state.

You can even use the animator for this to synchronize the colliders with your sprite frame by frame.

@Boothand
Copy link
Author

Hmm, forgot how much you can animate in Godot. I didn't find a way of changing the extents in the API, but I'll give it a try animating it!

@saturnian-tides
Copy link

saturnian-tides commented Sep 30, 2017

Assuming you are working with a RectangleShape2D you should be able to do the following from the script (though I do find the animator nicer to work with since its intuitive to overlay over your sprites):

myCollisionShape2D.get_shape().set_extents(my_new_extents)

https://godot.readthedocs.io/en/latest/classes/class_rectangleshape2d.html#class-rectangleshape2d

EDIT: And similarly for CapsuleShape2D in your case:

myCollisionShape2D.get_shape().set_radius(my_new_radius)
myCollisionShape2D.get_shape().set_height(my_new_height)

https://godot.readthedocs.io/en/latest/classes/class_capsuleshape2d.html#class-capsuleshape2d

@MateusMP
Copy link
Contributor

MateusMP commented Nov 7, 2017

Hey! I'm trying to fix this one, I'll comment again if I find anything useful.
(Not sure if you guys have any standard on how to assign this, I'm hero here to help!)

MateusMP added a commit to MateusMP/godot that referenced this issue Nov 8, 2017
Fix wrong col_obj access using wrong index variable.
MateusMP added a commit to MateusMP/godot that referenced this issue Nov 8, 2017
Fix wrong col_obj access using wrong index variable.
Related with issue godotengine#11695
@akien-mga
Copy link
Member

Fixed by #12757.

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

6 participants