Dificults with bullet behavior

Get help using Construct 2

Post » Mon Dec 12, 2016 3:18 pm

Hi guys, I'm strugling with something.

I'm testing and learning how to make a type of puzzle for my game (an oldshcool 8 directions rpg game). The thing is: I need to "kick" a block to one of the 4 directions (Up or Down or Right or Left), it will keep going until it hits the wall. When it hits, it stops, so I can kick to another direction, until it arrives at the objective area. The block only stops when it hits a wall.

What I did: Bullet behavior on the block i need to kick, the angle of motion is set by the direction i'm pressing on the keyboard, the Enable of Bullet is set when I click space bar and the characher is on collision with the block. Bullet is set to Disabled when it collides the wall. And then comes the problem, when it collides the wall, the block gets a litle trought the wall, but just some pixels. (As shown on IMG1).

IMG1
Image

If i kick right, it collides with the wrong wall. (As shown on IMG2).

IMG2
Image

What i need: A way to make one object dont get inside the other. I tried a few things and couldnt find any solution.
I can give more details if you guys need it.

Thanks and sorry about my bad english, hope you understand.
B
2
Posts: 3
Reputation: 156

Post » Mon Dec 12, 2016 4:04 pm

You could try the following:

Add instance variables "directionX" and "directionY" to the block
Set those variables at the start to 0

On moving block:
enable bullet behaviour;
if direction = up set directionY to -1,
if direction = down set directionY to 1,
if direction = left set directionX to -1,
if direction = right set directionX to 1

On block overlapping with wall:
disable bullet behaviour;
Set block (X,Y) to ((block.directionX*(wall.width+block.width)/2)+wall.X ,(block.directionY*(wall.height+block.height)/2)+wall.Y);
Set block.directionX and block.directionY to 0

This method assumes that your blocks and walls are positioned on a grid.
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Post » Mon Dec 12, 2016 8:48 pm

My solution is a bit complicated. Its basically adjusting after the fact by remembering what direction the kicked object came from by remembering the moving angle in a variable, and then nudging the object in the right direction. Its pixel perfect though. and the cap should explain it.
https://drive.google.com/open?id=0B3l68 ... zFMbF9pSDQ
B
6
S
2
G
2
Posts: 33
Reputation: 891

Post » Mon Dec 12, 2016 11:08 pm

mekonbekon wrote:You could try the following:

Add instance variables "directionX" and "directionY" to the block
Set those variables at the start to 0

On moving block:
enable bullet behaviour;
if direction = up set directionY to -1,
if direction = down set directionY to 1,
if direction = left set directionX to -1,
if direction = right set directionX to 1

On block overlapping with wall:
disable bullet behaviour;
Set block (X,Y) to ((block.directionX*(wall.width+block.width)/2)+wall.X ,(block.directionY*(wall.height+block.height)/2)+wall.Y);
Set block.directionX and block.directionY to 0

This method assumes that your blocks and walls are positioned on a grid.



Hi, thanks for the help.

Unfortunatly I didnt understand what the equation does, and its not working for me. I kick the block, when hits the wall, it desapear. More like it is random teleporting and then gone, but very fast. So I think it actually is calling the equation, but i'm entering something wrong. So, can you explain the equation to me, please?

Thanks again.
B
2
Posts: 3
Reputation: 156

Post » Mon Dec 12, 2016 11:15 pm

Message: zKewin can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Nifl wrote:My solution is a bit complicated. Its basically adjusting after the fact by remembering what direction the kicked object came from by remembering the moving angle in a variable, and then nudging the object in the right direction. Its pixel perfect though. and the cap should explain it.
https://drive.google.com/open?id=0B3l68 ... zFMbF9pSDQ


Thanks for the reply, I'll be looking into it.
B
2
Posts: 3
Reputation: 156


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 30 guests

cron