0 Favourites

Dificults with bullet behavior

  • 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

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

    IMG2

    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.

  • 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.

  • 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

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)