How to keep an actor's target from changing with every touch

zincotroidzincotroid Member Posts: 6
edited November -1 in Working with GS (Mac)
I'm sure that this is probably something very simple I'm over looking.

I want to spawn an actor when I touch the screen and I want that actor to move to the location I touched. The only problem is that if I touch anywhere else before the actor reaches the original location, it turns and heads for the new touch.

how can I set a touch as a target for one actor that will persist after the next touch?

Comments

  • synthesissynthesis Member Posts: 1,693
    you need to wrap the spawn rule inside a touch switch
    Have the touch activate a spawn boolean.
    game.spawnRequest=false

    Rule1: (in an invisible game sensor actor or on the background graphic)
    when background is touched:
    game.spawnLocX = touch.X
    game.spawnLocY = touch.Y
    game.spawnRequest = true

    Rule2: (on Actor)
    when game.spawnRequest = true
    spawnActor at game.spawnLocX and Y
  • TboneTbone Member Posts: 49
    I'm having a similar problem. I want to spawn an actor (bullet) in the direction of a touch. But when I touch again for the next shot, the first bullet changes direction towards the new touch along with the new bullet.

    My rules are:
    On touch shoot to true
    get x touch
    get y touch
    make direction vector to angle

    spawn bullet at direction
    change shoot to false.

    I think this is pretty much what synthesis has outlined above but it doesn' t work for me.

    Can anybody help with this?
  • TboneTbone Member Posts: 49
    thats awesome!

    thanks tsb, much appreciated.
  • JGary321JGary321 Member Posts: 1,246
    I do this in my game. Under the actor you need 2 attributes:

    X
    Y

    2 Rules:
    Change self.X to Touch1.X
    Change self.Y to Touch1.Y

    And then the move rule:
    Move To: X=self.X & Y=self.Y

    So this will make sure it uses the same coordinates regardless if you touch again or not. Depending on timing you may need to set a game attribute for your touches. Like:

    (This goes on your BG actor)
    When Pressed change game.X to Touch1.X & game.Y to Touch1.Y

    And then under your actor instead of :
    Change self.X to Touch1.X
    Change self.Y to Touch1.Y

    DO:
    Change self.X to game.X
    Change self.Y to game.Y

    Try the first way, but depends on how fast the timing is. See which way suits you.

    Hope this helps.
Sign In or Register to comment.