How do I get bullet behavior not to step into solids?

1 favourites
  • 9 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi everyone.

    I have an object with Bullet behavior (disabled) and another with Solid behavior. I am trying to make the bullet to stop moving when it is touching a solid and never considers moving if it is touching a solid.

    Here is a GIF of the problem:

    i.imgur.com/muMDiao.gif

    The circle is the Bullet in this case.

    So my code is this:

    i.imgur.com/lA4Nk5v.png

    But as you can see from the GIF no matter what, it still goes through the solid if I spam tap.

    I tried having a subevent checking if the bullet is overlapping a solid, it won't register the tap. But the problem then would be if the bullet touched the wall, stopped and now the player wants the bullet to move OUT of the wall, they can't because the tap is ignored.

    Any idea how I can resolve this issue?

  • At speed this high, even with stepping enabled the bullet will not be able to stop exactly at the edge of the solid object.

    You need to add an event that will "push" the bullet out of the obstacle. In a loop move the bullet backwards 1px and check if it's still overlapping the obstacle. When no longer overlapping - stop the loop.

    There may be better ways to do all this, for example with raycasting.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • At speed this high, even with stepping enabled the bullet will not be able to stop exactly at the edge of the solid object.

    You need to add an event that will "push" the bullet out of the obstacle. In a loop move the bullet backwards 1px and check if it's still overlapping the obstacle. When no longer overlapping - stop the loop.

    There may be better ways to do all this, for example with raycasting.

    The speed is set to 4000 which is the same speed in the Step Example in C3. I tried raycasting, didn't exactly work well (unless I did it wrong). I don't fully understand what you mean here with loop move the bullet. Could you elaborate please?

  • Here is an example:

    https://www.dropbox.com/s/80h6upcj4mjf9d9/BulletPushOutSolid.c3p?dl=0

    Thanks. Oh, I see now what you mean.

    I tried that. So the "bullet" in my case is the player and I am trying to create a dash behavior. So when I use the method you have right now, I end up with a weird bug.

    Say I dashed towards a box (from the GIF) and say I hit its left side (coming from the left). Now if I click above the top of the box, for some odd reason the player (bullet behaviour object) teleports to where I click. It happens randomly. Sometimes it happens, other times it doesn't. But usually it is when the object is stuck to the box on one side while I am clicking on the side next to it.

  • I would do this with LOS/raycasting and MoveTo behavior. Bullet at high speeds is too unreliable and hard to deal with.

  • I would do this with LOS/raycasting and MoveTo behavior. Bullet at high speeds is too unreliable and hard to deal with.

    Gotcha. Is there any way I can get the contact point of the raycast? Or perhaps get a point on a direction.

    Say, like in the GIF, I have the ball in the middle but tap on the black box. The raycast will detect collision and it won't move. Now if I can't get the contact point of the raycast, is there a way to say something like "Even if there is a collision with the raycast, move the ball X and Y pixels towards the contact point" for example?

  • object.lineofsight.hitX & object.lineofsight.hitY will give you the coordinates of the intersected raycast.

    You can also use object.lineofsight.hitdistance if you need a quick measure of the distance.

  • object.lineofsight.hitX & object.lineofsight.hitY will give you the coordinates of the intersected raycast.

    You can also use object.lineofsight.hitdistance if you need a quick measure of the distance.

    I didn't know that. Thank you very much!

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