tap location and shoot towards location

tollhousestudiotollhousestudio Member Posts: 166
edited November -1 in Working with GS (Mac)
is this possible? I'm trying to make it so that if you tap the screen a bullet will fire in the direction of where I tapped.

Possible? if so, could someone help out.

Thanks in advance.

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Haven't tried this, but here is what I would do. Create a game attribute called targetX and another called targetY (set these to real). Create a third game attribute called shoot and set it to boolean.

    Create a rule that says when mouse button is clicked (or touch is pressed)
    change game.targetX to touch.X
    change game.targetY to touch.Y
    change shoot to true

    then in your bullet place a move towards behavior. For x use game.targetX and y use game.targetY

    In your shooter create a rule that says:

    when game.shoot is true
    spawn bullet.
    change attribute game.shoot to false (so it doesn't just keep shooting)

    I'm at work and not on a mac so I can't test this. Seems like it should work. good luck!
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    I think I did what you're talking about in my game:
    http://gamesalad.com/game/play/26389

    is that what you mean?

    I created a few global attributes - shoot, x, y

    it was pretty easy, what I did was create a bullet, and define added two attributes to the bullet itself - X & Y.

    I added two change attribute rules -
    change self.X to game.X
    change self.Y to game.Y

    and a timer
    after 1 second
    destroy

    I also created an accelerate toward rule on the bullet towards self.X and self.Y

    then on your actor that shoots the bullet I had a rule
    when game.Shoot = 1
    spawn bullet

    and then to actually capture and shoot, I created an actor called Capture that was the size of the background. On that I created a rule:

    when actor receives touch
    change attribute game.Shoot = 1
    change attribute game.X to device.X (device - touch 1 - y)
    change attribute game.Y to device.y (device - touch 1 - y)

    something like that anyways, this allows you to shoot multiple bullets in a row, each going to it's own direction. My way will have the bullets continue off the screen, but if you do Move in stead of Accelerate, it will stop wherever you clicked.

    I'm pretty sure Tshirtbooth or someone made a quick tutorial, it should be in the games section
  • tollhousestudiotollhousestudio Member Posts: 166
    I tried this and Its crashing the game. I'm clearly not doing something right.

    Any other suggestions? is this the right way of doing it or is there some missing info?
Sign In or Register to comment.