We've now seen both static and dynamic physics objects in GameMaker, but what happens when we want the best of both worlds? Let's take a look at how to create a platform that can move and affect other objects via collisions but is immune to said collisions.
Again, we'll be using our existing physics environment, but this time, we'll need a new object. Create a sprite that is 128 px wide by 32 px high and assign it to an object called obj_platform
. Also, create another object called obj_kinematicParent
but don't give it a sprite. Add collision events to obj_staticParent
, obj_dynamicParent
, and itself. Make sure that there is a comment in each event.
In
obj_platform
, add a Create event.Drag a code block to the Actions box and add the following code:
var fixture = physics_fixture_create(); physics_fixture_set_box_shape(fixture, sprite_width / 2, sprite_height / 2); physics_fixture_set_density(fixture, 0); physics_fixture_set_restitution(fixture...