Jump to content


Photo

Making a block pushable in 4 directions


  • Please log in to reply
5 replies to this topic

#1 KOOPA

KOOPA

    GMC Member

  • GMC Member
  • 463 posts
  • Version:GM8

Posted 15 May 2012 - 07:43 AM

How do I make a block pushable in all 4 directions

when my player_block collides with push_block I want the push_block to move in the direction player_block is moving
  • 0

#2 M.D.Simmo

M.D.Simmo

    -- ·- - -

  • GMC Member
  • 204 posts
  • Version:GM8.1

Posted 15 May 2012 - 08:40 AM

if your player_block is actually moving (not just running an animation):
// collision with player_block
    x += player_block.x - player_block.xprevious;
    y += player_block.y - player_block.yprevious;

Edited by M.D.Simmo, 16 May 2012 - 06:13 AM.

  • 0

#3 KOOPA

KOOPA

    GMC Member

  • GMC Member
  • 463 posts
  • Version:GM8

Posted 15 May 2012 - 09:53 AM

Nope this push_block is not moving nor does it have an animation
it is a static block I want it to move with the player_block if the player is pushing into it
  • 0

#4 M.D.Simmo

M.D.Simmo

    -- ·- - -

  • GMC Member
  • 204 posts
  • Version:GM8.1

Posted 15 May 2012 - 10:21 AM

Nope this push_block is not moving nor does it have an animation
it is a static block I want it to move with the player_block if the player is pushing into it


sorry, when I asked about the push_block, I meant the player_block.
I've fixed the code to be correct and should work for the situation.
  • 0

#5 KOOPA

KOOPA

    GMC Member

  • GMC Member
  • 463 posts
  • Version:GM8

Posted 16 May 2012 - 04:15 AM

thanks your code didnt work but I changed the player_block.x and player_block.y to push_block.x and push_block.y and now it works perfectly

But if only it moved smoothly and not like in a jolty motion
  • 0

#6 M.D.Simmo

M.D.Simmo

    -- ·- - -

  • GMC Member
  • 204 posts
  • Version:GM8.1

Posted 16 May 2012 - 06:29 AM

But if only it moved smoothly and not like in a jolty motion


if your push/player block uses vspeeds and hspeeds to move around, this code makes it a little more smooth.
// step event of push_block
if (place_meeting(x,y,obj_push)) {
    hspeed = obj_push.hspeed;
    vspeed = obj_push.vspeed;
} else {
    speed *= 0.9;
    if (speed < 1) {
        speed = 0;
    }
}
(The push_block and player_blocks may need to be switched around)

Edited by M.D.Simmo, 16 May 2012 - 06:32 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users