Fangames > Programming Questions
pushable blocks
cl0udi:
so how do i make those blocks that you can push around and they fall when pushed off an edge?
klazen108:
Make the block.
Give it the "block" object for its parent.
Check the "solid" checkbox
Step Event of your block:
--- Code: ---//step event of block
fallSpd=3;
//pushable
if (place_meeting(x-3,y,player) && player.h == 1) move_contact_solid(0,3);
else if (place_meeting(x+3,y,player) && player.h == -1) move_contact_solid(180,3);
//fallable
if (place_meeting(x,y+1,block)) vspeed=0;
else move_contact_solid(270,fallSpd);
--- End code ---
Player's Step Event:
Replace this line:
--- Code: ---var L,R,h;
--- End code ---
With this line:
--- Code: ---var L,R;
--- End code ---
Player's Begin Step Event:
--- Code: ---h=0;
--- End code ---
Some notes:
* This assumes you don't mind that the block falls at a constant speed, not affected by gravity
* If the block covers a spike, you will still die to the spike. This is true for objects with a "block" parent, and you will have to move the playerkiller collision event to the end step event (I can provide more information if this is the case)
* I just tested this in the yuuutu engine, and it seems to work just fine.
* The block moves 3 pixels at a time, like the kid, so be wary of align issues (it won't fall in a 1 block wide hole unless that hole is at the same pixel align as the starting point of the block
Let me know if you have any problems!
Derpyhoovesiwbtg:
Something else, in Dark Blue, theres that room with the pushable block and the button that activates a trigger. How do you let the pushable block activate the button?
infern0man1:
Though it may not be the most effective way to make this happen, this is what I would do:
In the button, create a trigger variable and set it to 0. Then have the trigger variable set to 1 when the block collides with the button. In the object triggered, make it so the object does whatever it should do when the variable is set to 1.
Hopefully that makes some sense; I'm not the best with GM.
Derpyhoovesiwbtg:
Thanks! Im gonna test it soon.
Navigation
[0] Message Index
[#] Next page
Go to full version