Legacy GM Falling Objects

J

jvks2

Guest
Hello everyone,

I am trying to figure out in a platforming room with physics how to have a objectA connect to the ceiling and the player character can shoot the ceiling causing the ceiling to break and objectA falls to the ground but stops at the floor. The room is persistent and has the following code with regards to movement for the player.

//Platform Movement - Player Movement

/*Get inputs
Scr_GetInputs();
*/

//Get Inputs
var xPlatform, yPlatform;
xPlatform = keyboard_check(ord("D")) - keyboard_check(ord("A"));
yPlatform = keyboard_check(ord("S")) - keyboard_check(ord("W"));

x += xPlatform * walkingSpeed;
y += yPlatform * walkingSpeed;

key_jump = keyboard_check_pressed(vk_space);

/*might need later
key_w = keyboard_check(vk_up);
key_s = keyboard_check(vk_down);
*/

//React to inputs
if (vsp <10) vsp += grav;

//Normal Movement
hsp = xPlatform * walkingSpeed;

vsp += 0.2;
if (place_meeting(x,y+1,Obj_wall))
{
vsp = key_jump * -jumpspeed
}

//Horizontal Collision
if (place_meeting(x+hsp,y,Obj_wall))
{
while(!place_meeting(x+sign(hsp),y,Obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,Obj_wall))
{
while(!place_meeting(x,y+sign(vsp),Obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;

Thanks,

Jvks2
 

Carolusclen

Member
1 way to do this is the object on the ceiling, have it activate its gravity only when its shot.
and as for the collision with the floor, use the same code you use for the player's interception with the floor :)
 

Roderick

Member
1 way to do this is the object on the ceiling, have it activate its gravity only when its shot.
To elaborate: Give it a create event that says

Code:
falling = false;
When you want it to start falling, set falling to true.

Then, instead of just having your fall code running every step, wrap it in a conditional:
Code:
if (falling == true)
{
 // fall code goes here
}
 
J

jvks2

Guest
Thanks both of you, I will try these over the weekend and let you know if I succeed.
 
Top