Spawn actor from main actor and move to touch

billpaternobillpaterno Member Posts: 26
edited November -1 in Working with GS (Mac)
I am trying to set up some behaviors so that when a button is pushed, a projectile actor spawns from my main actor, constrains its XY to the main actor until another point is touched on the screen...then I would like the projectile actor to move to the point touched.

Right now I have a boolean game attribute for spawning that is set to false. When the button is pushed, that attribute is set to true, which spawns a projectile actor from my main actor. Then in the projectile actor behaviors, I have two rules. One which contrains XY to main actor for .1 seconds (if spawn=true) and then another rule (move to) that follows the XY of the mouse. However, if I move the mouse around, the projectile follows the mouse until it hits the cursor.

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    Within the spawned actor,
    set two constrain Attributes, one for the playerX and on for the playerY.

    3 attributes, targetX, targetY, and a boolean: movingToTarget

    and a Rule that says:

    ALL
    When the MOUSE button is DOWN
    When movingToTarget is FALSE
    Change Attribute: targetX to Mouse.PositionX
    Change Attribute: targetY to Mouse.PositionY
    Change Attribute: movingToTarget to TRUE

    And another Rule

    When movingToTarget is TRUE
    MoveTo targetX,TargetY
  • billpaternobillpaterno Member Posts: 26
    It's not working for me.

    What I have right now is the spawned actor with the following behaviors:
    Constrain X, Constrain Y to PlayerX and PlayerY
    Rule: When game.movingToTarget is true, move to game.targetX, game.targetY

    For the button I have:
    When ALL..mouse button down, mouse position inside, game.movingToTarget is false,
    Change boolean game.Spawn to true
    Change game.targetX and Y to game.Mouse.PositionX and Y
    Change game.movingToTarget to true

    And for the player actor I have:
    When game.Spawn is true, after .5 seconds (timer), spawn actor

    When I press the button, projectile spawns on top of player actor and tracks with him but the second click does not direct the projectile.

    I know I am missing something stupid here.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    just to confirm, on the second click, you do NOT have mouse button inside...
  • billpaternobillpaterno Member Posts: 26
    correct
Sign In or Register to comment.