How would you do this?

So I have a Turret enemy that I want to be able to look in each direction and shoot at the player.
My Turret has a base, and the cannon part will swivel looking in a 180 degree range.

How could I make it so that it targets the player and fires. Or just fires a few times in one direction then changes where it's looking and shoots in that direction?

Please help thank you

Comments

  • NNterprisesNNterprises Member, PRO Posts: 387

    I'm going to take a wild generic guess, but there may be a better way to do this.

    Make a global/scene real attribute for Enemy position x = Ex
    Make a global/scene real attribute for Enemy position y = Ey
    Make a circle actor for the range of your turret, make Alpha = 0 (so it cannot be seen), and put it at the center of your turret.

    Make a BOOLEAN attribute called IN RANGE

    In the enemy actor, make a rule that says:

    -If actor collides with actor of type CIRCLE,
    --Change attribute IN RANGE to TRUE
    --Constrain attribute Ex to self.postition.x
    --Constrain attribute Ey to self.postition.y
    ++
    -ELSE change cttribute IN RANGE to FALSE

    On the turret actor, make a rule that says:

    -If attribute IN RANGE is TRUE
    --Constrain Attribute self.rotation to (180/pi)*arctan((Ey - self.position.y)/(Ex - self.position.x))

    This should work from my calculations.... if it goes the other way you may have to change a minus sign.

    But yea there's probably an easier way, I don't have experience in this yet

Sign In or Register to comment.