• 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!

GML Changing the fixture shape

Hey everyone!

So I'm attempting to include som physics objects in my game but I'm having a bit of a tough time with a sliding door.

Non physics object collide just fine because to collision shape matches the image_index. Physics object are a different story.

Now I may be going about this all wrong but my idea was to redraw the collision shape for the door based on the image index. Here is the code to draw the initial shape for the closed door:

Code:
physics_fixture_set_box_shape(fix_door);
physics_fixture_add_point(fix_door, 1,0);
physics_fixture_add_point(fix_door, 64, 0);
physics_fixture_add_point(fix_door, 64, 23);
physics_fixture_add_point(fix_door, 1, 23);
GMS2 tells me the shape cannot be concave or anti-clockwise.

I'm probably doing this wrong.

Is there a better solution?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I'm probably doing this wrong.
Yup... Sorry! :)

Okay, so, first, ask yourself WHY you want to use physics for the door. I say this because Physics is really meant to be used for games that need to simulate "real-world" interactions, but many people try to use it as an easy (Nope!) fix for collisions and other stuff.

Second, if you decide you DO need physics, then you need to reconsider your approach. First of all, the functions you show are for unbound fixtures. What this means is that there are two types of fixtures: unbound and bound. These are like "objects" and "instances" in that you create an unbound fixture (which would analogous to an object) and then bind a copy of it to an instance (where the bound fixture becomes like an instance). So all the code you posted above is doing is re-defining the unbound fixture without actually changing the bound fixture.

So, to do what you seem to be trying to do, you'd need to either:
  • unbind the fixture, change it's shape, then rebind it every step (not recommended as it can cause issues since in the real world objects don't change their physical properties every /60th of a second!)
  • use the physics functions and variables to change the position/rotation of the fixture and then work out how to draw the sprite correctly
  • not use physics and stick with the regular GM collision system

Hope that helps!
 
Thanks!

I had a suspicion I was going the wrong way.

I'll try to just trigger the physics object to move. I have non-physics objects with proper collisions but also want some objects to have real world physics. So I don't want physics object just rolling right through a door.
 
Top