S
Sweedums
Guest
Hey there folks, i'm pretty new to GMS (and programming in general) but i'm trying to make a simple top down physics based puzzle game.
The core mechanic is that I want the player to be able to squash themselves flat or thin to squeeze through tight spaces and interact with things, i also want them to be able to inflate and deflate (imagine a puffer fish) however I'm having some issues with the changing of the collision bounding box whenever the player object changes size.
I looked up a few old threads dealing with similar situations but I'm hitting a brick wall so thought i'd try a new thread with my specific issue.
to get started, i've put in a key press event which triggers the player sprite to scale to double size (sudden inflation) and I'm creating a new fixture that then matches that size.... this seems to be working, however i also then have an alarm which triggers, causing the player to shrink back down to their original size (suddenly deflating... imagine holding breath, and then after a set time having to let it all out) and at this point, the large fixture still seems to be present, and so the player object, while visually being back to its normal size, has a large invisible collision box around it. I suspect i'm simply misunderstanding how to un bind, and rebind a new fixture, so here's my code for both events:
Key press (F) "Enlarge"
Alarm[0] "Shrink"
Now if i'm understanding this right, im applying a new, large fixture called "fixturefat" and then trying to replace it with the standard sized "fixture".... but I suspect I'm being dumb somewhere in here. I have unchecked the "Uses physics" box on the player object and created the initial fixture in the code as I read that that can cause some issues.
Thanks in advance for any help!
The core mechanic is that I want the player to be able to squash themselves flat or thin to squeeze through tight spaces and interact with things, i also want them to be able to inflate and deflate (imagine a puffer fish) however I'm having some issues with the changing of the collision bounding box whenever the player object changes size.
I looked up a few old threads dealing with similar situations but I'm hitting a brick wall so thought i'd try a new thread with my specific issue.
to get started, i've put in a key press event which triggers the player sprite to scale to double size (sudden inflation) and I'm creating a new fixture that then matches that size.... this seems to be working, however i also then have an alarm which triggers, causing the player to shrink back down to their original size (suddenly deflating... imagine holding breath, and then after a set time having to let it all out) and at this point, the large fixture still seems to be present, and so the player object, while visually being back to its normal size, has a large invisible collision box around it. I suspect i'm simply misunderstanding how to un bind, and rebind a new fixture, so here's my code for both events:
Key press (F) "Enlarge"
Code:
image_xscale = 2
image_yscale = 2
physics_remove_fixture(o_player,fixture)
fixturefat = physics_fixture_create();
physics_fixture_set_box_shape(fixturefat, sprite_width / 2, sprite_height / 2);
physics_fixture_set_density(fixturefat, 1);
physics_fixture_set_restitution(fixturefat, 0.2);
physics_fixture_bind(fixturefat, o_player);
physics_fixture_set_linear_damping(fixturefat, 1)
physics_fixture_delete(fixturefat);
alarm[0] = 60;
Code:
image_xscale = 1
image_yscale = 1
physics_remove_fixture(o_player,fixturefat)
fixture = physics_fixture_create();
physics_fixture_set_box_shape(fixture, sprite_width / 2, sprite_height / 2);
physics_fixture_set_density(fixture, 1);
physics_fixture_set_restitution(fixture, 0.2);
physics_fixture_bind(fixture, o_player);
physics_fixture_set_linear_damping(fixture, 1)
physics_fixture_delete(fixture);
Thanks in advance for any help!