How do i create, ai that shoots upon variables

AjBlueAjBlue Member Posts: 215
edited November -1 in Working with GS (Mac)
in my game i need to create an enemy, when spawned it moves straight to the other side and when another actor gets within a certain distance, for the enemy to shoot at the actor. any ideas?

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    You use magnitude to determin how close or far something is from something else. And then trigger your behaviors at the position you want.

    Usage: magnitude(x,y)

    Find the length of a line segment from the origin, (0,0), to the given point. You can include an offset,(x',y'), to find the length between the two points. i.e. magnitude(x-x',y-y')

    Example: If I wanted to find the length between my actor at coordinates (25,30) and another actor at coordinates (100,240), I would use the expression magnitude(25-100,30-240)

    http://gamesalad.com/game/1804
  • AjBlueAjBlue Member Posts: 215
    ok so then, how would i get the object to shoot in the direction of the enemy inside of the magnitude range?
  • magic101himagic101hi Member Posts: 713
    Rules for shooting actor:

    First things first create an actor called projectile(the bullet your guy will be shooting)
    and 2 attributes named HeroX ,and HeroY
    `

    //Inside the hero

    =====constrain attribute=====

    Self.Position.X - to - Game.HeroX

    =====================

    =====constrain attribute=====

    Self.Position.Y - to - Game.HeroY

    =====================

    //inside the enemy

    -------Rule---------

    actor - overlaps or collides with - actor of type - range

    -------------------

    ====Timer====

    Every 1 second

    ====Spawn actor====

    Projectile

    ================

    ===========

    //Inside Projectile Actor

    ====Move To====

    Game.HeroX

    Game.HeroY

    `

    Hope I helped....

    -Josh

  • AjBlueAjBlue Member Posts: 215
    so... i successfully managed to make everything stop working. i must have done something wrong

    when you say make an attribute, what type should it be?
Sign In or Register to comment.