Shoot within angle

  • Hi!

    In my Iphone game i have a tank.

    I want the tank "only" to shoot when a enemy is within 5 degr of the tank turret, no matter how far the enemy and the tank turret are away from eachother.

    I have seen the "is between angle conditions etc".

    However i havent found a solution to this.

    Anyone have some insight?

    Thanx!

  • Sprite has a condition to compare if it is within a certain angle.

    sprite angle is with in 5 of angle(Sprite.X,Sprite.Y,Sprite2.X,Sprite2.Y): do stuff

  • I tried that but it only applied to when the other sprite was on the + side of the Y.

    I need something to measure the angle in full 360.

    Or i am doing something wrong?

  • Is the enemy "on-screen" or qhen you say no matter how far, that includes "off-screen" enemies?... if it's the first scenario, maybe you can try this:

    http://dl.dropbox.com/u/103248101/capx/5degrees.capx

    it's just a sprite triangle-shaped acting as the aim of the tank's turret. The triangle has a 5� angle facing the tank, so anything overlapping that "aim" is within 5� of the tanks turret (that if my trigonometry doesen't fail me)

    I supposed it was a top-viewed tank... Hope it works for you

  • Thanx danuyos

    Im going to try it out!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Nimtrix

    That also seems the right way of doing things.

    Thanx!

    Im of testing!

  • Woops, accidentaly deleted my post by misclick:

    You can use the anglediff expression:

    +System: Every tick
    -> Set a to angle(Turret.X, Turret.Y, Target.X, Target.Y)
    -> Set a0 to default angle
    
    +System: Compare two values (anglediff(a, a0) <= 5)
    -> Rotate towards a
    +Else:
    -> Rotate towards a0

    edited><editID>Nimtrix</editID><editDate>2012-09-20 21:20:08</editDate></edited>

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