How do I grid move and push object

Get help using Construct 2

Post » Tue Apr 07, 2015 9:07 pm

i am trying to set up a player movement routine where by the player sprite (32x32) moves 1 grid space (32x32) on the press of the arrow keys, but can not move through a solid wall or obstacle, and can push another sprite (32x32)

here is my logic..:

  • the green square is controlled by the player
  • the purple square is pushed in the direction of the green square movment
  • neither square can pass through the black square
  • the green square can not pass through the purple square

when i add a single direction my logic works perfectly: http://zordorkproductions.com/tests/gridpush.capx

but when i add all 4 directions things goto pot: http://zordorkproductions.com/tests/gridpush1.capx

if anyone can point into the right direction of where i have gone wrong it would be much appreciate.
B
10
S
4
G
3
Posts: 53
Reputation: 2,613

Post » Thu Apr 09, 2015 8:04 pm

i have been trying out different things and come up with a routine to push the block around:

http://zordorkproductions.com/tests/gridpush2.capx

this routine works great for 1 movable block but goes wrong when i add extra pushables.. also i can not work out the collision with walls...

please can someone point me in the right direction
B
10
S
4
G
3
Posts: 53
Reputation: 2,613

Post » Fri Apr 10, 2015 9:37 pm

OK let me if I can ask my question in a more simple way:

I have a controllable block which is 32px x 32px (sprite2)
I have a obstacle block which is 32px x 32px (sprite3)
I have a pushable block which is 32px x 32px (sprite4)

I am moving sprite2 with:
if cursor key pressed move in that direction by 32px add 1 to movecount (this is working)

Logic I want to include:

1) if sprite 2 is in contact with sprite3 it can push it in the direction of the cursor key (this is working for 1 instance of sprite3, but not for multiple instances of sprite3)

2) sprite2 can not move through sprite4 (not working)

3) sprite2 can not push sprite3 through sprite4 (not yet programed)

4) Sprite2 can not move through sprite3 (not yet programed)

I would really appreciate some input on this
B
10
S
4
G
3
Posts: 53
Reputation: 2,613

Post » Sat Apr 11, 2015 12:14 am

Move Push

The main thing, that even stumped me for a few minutes was the collision box (sprite -> image editor -> collisions).. of course this by default is set to the sprite width and height.. look in here and you'll notice I scaled the collision box down a few pixels (hence the overlapping at offset 5/-5 in the events).

I'm not sure what you wanted if while pushing a block in some direction and another movable block is in the way.. should it push that one too? or stop? well... that's your homework if you need that :}
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Sat Apr 11, 2015 3:17 pm

that hadst even crossed my mind, this gives me something to play around with. Thanks
B
10
S
4
G
3
Posts: 53
Reputation: 2,613


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], Janaina and 2 guests