Legacy GM Physics Fixture Changing

K

KriLL

Guest
Hi guys,

I have a bit of a problem and I was wondering if anyone know if this is the normal behavior.

I have a block that I define all the physics fixtures for it via code.

I then have a collision with another object which should then cause the block to change its physics fixtures.
To summarize the code

  • Define fixtures for block
  • Collision occurs
  • Delete current fixture
  • Create new fixture and assign to block
Now the problem seems to be that the density, restitution and friction change but the angular and linear dampening are not changed.

Is this correct?


Code below if that helps.


///Physics Fixtures defined

var blockfixture;
blockfixture= physics_fixture_create();
physics_fixture_set_box_shape(blockfixture, sprite_get_width(sprite_index) / 2, (sprite_get_height(sprite_index) / 2)-1);
physics_fixture_set_density(blockfixture, 20.0);
physics_fixture_set_restitution(blockfixture, 1);
physics_fixture_set_linear_damping(blockfixture, 1);
physics_fixture_set_angular_damping(blockfixture, 1);
physics_fixture_set_friction(blockfixture,50);
physics_fixture_set_awake(blockfixture, true);


my_fixture = physics_fixture_bind(blockfixture, id);
physics_fixture_delete(blockfixture);



Then when a collision occurs it runs the following:

///Remove fixture

physics_remove_fixture(id, my_fixture);


///Create new fixture

var changefixture;
changefixture= physics_fixture_create();
physics_fixture_set_box_shape(changefixture, sprite_get_width(sprite_index) / 2, (sprite_get_height(sprite_index) / 2)-1);
physics_fixture_set_density(changefixture, 5.0);
physics_fixture_set_restitution(changefixture, 0);
physics_fixture_set_linear_damping(changefixture, 0);
physics_fixture_set_angular_damping(changefixture, 0);
physics_fixture_set_friction(changefixture,0);
physics_fixture_set_awake(changefixture, true);

my_new_fixture = physics_fixture_bind(changefixture, id);
physics_fixture_delete(changefixture);


Thanks
 
Last edited by a moderator:

KurtBlissZ

Member
In the collision wouldn't you have to do physics_remove_fixture(id, my_fixture); and not physics_remove_fixture(id, fixHeavy); Unless somewhere else fixHeavy is set to my_fixture.

I'm a newbie when it come to physics so. :p. Hope that helps.


Edit: And if that doesn't work is there a reason why you go from using my_fixture to my_new_fixture.. You have something in place so this code is only ran once in the collision and not every time it collides? Maybe that might screw up some of the physics if it keeps recreating or creating new fixtures. Again not much experience with physics.
 
K

KriLL

Guest
Hi, thanks for your reply. Yes you are correct but that is just a mistake typing out the code from the game on my behalf. The code removes the correct fixture. The problem is actually changing the linear and angular dampening once a new fixture is bound to an object.

I think it may be a limitation in GMS based on the fact that there are 3 other commands you can use elsewhere.

Physics_get/set_density, restitution and friction. These commands don't exist for linear and angular dampening so it would seem to me that once bound these cant be changed? Would be good if anyone could confirm that :D


In the meantime I made a concession to make sure that the angular and linear damping at turned off (set to 0) which doesnt seem to make much difference to both fixtures.

cheers
 
K

KriLL

Guest
Cool thanks for your confirmation guess im not going mad afterall :)
 

KurtBlissZ

Member
Oh I just got it working, I had to set phy_angular_damping instead of using the set function... There is also a phy_linear_damping variable you can change too
 
K

KriLL

Guest
Oh I just got it working, I had to set phy_angular_damping instead of using the set function... There is also a phy_linear_damping variable you can change too

Oh great thanks very much will give that a whirl cheers :)
 

hippyman

Member
My advice is this. Since you aren't actually changing the shape of the fixture, but rather the properties of it, why don't you just change those instead? You don't actually need to destroy and remove the fixture to change the properties and since the shape is the same for both there's no need to waste the processing power.
 
Top