GML How Do I Change Physics Collision Shape Through Code?

N

Nicholas Rinella

Guest
This is my first post on the GameMaker Forum,

I'm having a lot of trouble trying to change the size of my players collision shape. (a square in this case) I've try'ed to change the image_xscale and image_yscale (they clearly just effect the sprite mask not the physics mask) and I've try'ed using fixtures but I'm not to familiar with the physics engine yet so please forgive my ignorance if there is a simple fix to my problem.

Any help would be greatly appreciated, just to be clear I'm trying to shrink the size of my players physics collider through code.
 

Jezla

Member
To change an object's fixture, you first have to unbind the current fixture, then define and bind a new fixture. Be aware that if the properties of the new fixture are different, the object will react differently to forces, so be sure to plan accordingly.

If you've defined your initial fixture via the object editor, you'll have to uncheck the "uses physics" box and define your initial fixture via code instead, as you'll need the id of the bound fixture in order to unbind it.
 
N

Nicholas Rinella

Guest
Thank you very much for replying. Hopefully this fixed my problem
 
N

Nicholas Rinella

Guest
Okay, im still having some issues...
I turned off uses physics
Then I set a fixture in the create event for my player and bound it to my player in the same event.

This works fine

But if I try to use physics_remove_fixture to remove the fixture from my player it doesn't do anything and keeps the original physical properties originally set.

I'm not entirely sure how to fix this because it just seems like the function to remove the fixture isn't being called.
 

Jezla

Member
Are you storing the id of the bound fixture and using that id when you remove it? Example:

Code:
//When you bind the fixture in create event
//Set up properties code here...
my_fix = physics_fixture_bind(fix, object);

//When you need to remove the fixture
physics_remove_fixture(id, my_fix);

//Define and bind the new fixture...
The physics_fixture_bind function returns a unique id for the bound fixture. This id is what you'll need to remove from the object. You don't necessarily have to call the remove function from that instance, so long as you know the instance id and that of its fixture and access them properly.
 
Top