how do i make a bullet object restrict its directions to only 4 or 8 angles?

0 favourites
  • 8 posts
From the Asset Store
Character Sprite Pack: Walk 4 Directions made in illustrator
  • im describing a bouncing object which can only move on 4 or 8 directions (will want both versions for my game). want to be able to restrict to say only diagonals, only horizontals, or horizontals AND diagonals.

    ive found a few solutions by using 'is object overlapping at offset', so i test whether the bullet it hitting a wall or a floor/ceiling, so the angle can be adjusted appropriately.

    (eg. if object is moving at an angle of 45*, if it hits a floor it turns to 315*, if it hits a wall to its right it turns to 135*)

    it works for the most part but has occaisional errors where it seems to bounce the wrong way.

    so was really looking for the most simple equation or simple method to handle this style of movement

    thanks for anyones help with this

  • You can try snapping the angle to 90 or 45 degrees on every tick, or on bounce off solid.

    Set angle of motion to round(Self.Bullet.AngleOfMotion/45)*45

  • hey thanks for the reply!

    yes ive tried those kinds of equations too and they dont seem robust enough. for some reason even with that exact equation running every tick, the objects are able to slip out of the 45* lock.

    it also needs a different equation for if its restricting to only 4 diagonal directions. setting it to "(round/90*90)" and then just adding +45 to the angle doesnt work so well because your only rounding the angle up, if that makes sense

    thanks for your help tho!

  • That expression worked well in my test. Make sure the collision polygon of the sprite resembles a circle. You can add more points to it if needed.

    Another solution is to calculate reflection angle after every collision with a wall. I made a demo some time ago, you can open it in free version of Consturct 3:

    dropbox.com/s/b7q3vofq8ujqxze/ReflectionAngle.c3p

  • thanks for sharing! thats a very interesting prototype..

    only thing is it doesnt seem to have the previously mentioned expression used in it. and the bullet didnt seem to restrict down to 4/8 directions.

    thanks for sharing tho its definitely an interesting approach, to check to see if a value is clockwise or not from an angle ect.

    i found an approach using platform movement on bullet object instead to interesting effect, and using "is on floor" and "is against wall" to test the angle that the bullet was hitting a wall from

    this is an example of the 4 directional diagonal movement i was trying to achieve

    dropbox.com/s/5vd5dnaitcktkcf/robust%20angle%20bullets.capx

    thanks again

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • only thing is it doesnt seem to have the previously mentioned expression

    Yes, because it's a different method :)

    and the bullet didnt seem to restrict down to 4/8 directions.

    It demonstrates how to make geometrically perfect reflection. If you place all your walls at 90 degrees and launch the ball at 45 degrees, it should always reflect at 45 degrees intervals.

  • I changed your demo, have a look:

    dropbox.com/s/usqdg21t6rab1ev/robust%20angle%20bullets.capx

  • nice, thanks again!

    yeah i agree it works almost perfectly, but if you look closely theres very occasionally some sort of mis calculation where a bullet will bounce unnaturally (ends up turning around 180* rather than turn 90 clockwise or counter cw)

    normally that wouldnt be a big problem, but the effect im going for in my game is a kind of rapid fire laser that bounces around corners. if a single bullet bounces off (which it will reliably given the number of bullet objects being fired) then it is very noticible

    thanks for your help again tho, perhaps a 'for each' event attached to it might stop it from happening, will play around with it more

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