• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Unbinding physics fixtures from objects

Hi all.

I'm trying to restore an object to normal behaviour after removing a physics fixture from it but I'm unable to do so. It's for a track editor that I'm working on - The desired behaviour is that a track wall object follows the mouse until it is placed (working correctly) and then after it is placed it has a physics fixture bound to it so that cars will collide with it (which is also working correctly) but if I want to then 'pick the object up' and move it again I can't get it to follow the mouse even after removing the bound physics fixture from it.

It's like the object is still physics enabled despite me unbinding the fixture. Happy to supply code to help here - Is there something that I'm missing? Is there a way that I'm unaware of to 'completely un-physics' an object and restore it to normal behaviour where x and y properties can be adjusted normally. Thanks in advance for any help anyone can give me here!
 
Thank you. I'll look to add my code as soon as I can. To your knowledge do you know if what I'm saying should be possible assuming the code is correct? I'm not able to do so at the moment but I'll add the code as soon as I can. Thanks. :)
 

Jezla

Member
Well, I just ran a quick test with grabbing and dragging a physics object. Observations: I didn't need to remove the fixture to drag it around. If you're doing something like x = mouse_x, y=mouse_y to drag it, make sure you use phy_position_x and _y instead.

If you don't want the instance to interact with the physics world, then rather than removing the fixture, set phy_active = false while you're dragging it, and back to true when you place it. This sounds like what you want to do, now that I read your question again.

Edit: Corrected wrong information. Even if physics is inactive, you still have to use the physics position.
 
Last edited:

Bart

WiseBart
The instance is probably still physics enabled because, underlying, Box2D uses a body that stores an instance's physics properties such as position, velocity, ... That body seems to be destroyed only when the instance is destroyed, even when you unbind all fixtures.
Therefore, the most convenient way to do this might be to fully destroy the physics-enabled instance and create an all new one instead each time.
When dragging, you could show a placeholder sprite or use an instance of another, non physics enabled object (a 'blueprint' without physics).
Best only use non physics enabled objects while editing.
 
Thanks for the replies guys. Bart yes that's what seems to be the case. I was hoping to avoid having to destroy and recreate the object because I'm using a vertex based method to create the track and all the vertex objects are 'connected' to each other by pairing them to each other using variables within each vertex object. Destroying one would mean having to update the variables in the others to be the new vertex object created in place of the old one which could become pretty messy if doing it for a selection. In light of this though I've thought of another way though (in line with what you're saying) where instead of binding the fixture to the vertex object I instead create an entirely new object and bind it to that. I can then 'pair' the new physics enabled object to the vertex object and then when I pick the vertex up it will destroy the new object rather than have to be destroyed itself, keeping physics off the vertex object entirely. Thanks for your help guys and taking the time to reply. Very much appreciated. :)
 
Top