How to spawn actor in direction of mouse

abhi19abhi19 Member Posts: 9
edited November -1 in Working with GS (Mac)
I've just started using gamesalad and am having problems with a part of my game.
I want to spawn an actor and have it move in the direction I clicked my mouse. Something like V for Vortex did the portal (vortex) spawning.
Also how do I constrain the distance it goes? Like I only want it to go out a few units.

Hopefully I posted in the right place.

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    I think you can create two real game attributes (spawnX and spawnY).

    Then have an invisible actor the size of the screen with a rule that says when touch is pressed

    -change spawnX to game.touch1.X
    -change spawnY to game.touch1.Y

    Then in the invisible actor that spawns the object have a spawn behavior and use spawnX and spawnY in the position section of the spawn behavior and be sure to change it from actor to scene.

    This will make the spawned object appear at the spot that you touched.
  • abhi19abhi19 Member Posts: 9
    Thanks for the response.
    But I think I misled you with my question. I was thinking the actor would spawn in a set spot, say the player, and then move at the direction of my mouse.

    Thanks
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    hey, I think you PM'd me on touch arcade.

    What I do is pretty simple. I have 2 actors, a player and a bullet. In the bullet actor I created two custom attributes (X and Y). I also created three global attributes, Touched, X and Y.

    When the user touches the screen it sets Touched to 1, and x to game.touch1.x and y to game.touch1.y (I'm sure of the exact names).

    On the player I have a rule that says when Touched = 1 spawn bullet

    On the bullet I have a few rules:
    change attribute self.X to game.X
    change attribute self.Y to game.Y

    Accelerate To self.X & self.Y at whatever speed you want. If you want your bullet to stop where you click, use Move To instead of Accelerate To.

    I then have a timer that says after 2 seconds destroy actor.

    Doing the above will let you click a bunch of times and all the bullets will go to their own location using the self.X and self.Y attributes.

    There was a similar project I looked at for this, but it's been awhile, maybe someone else remembers?
  • abhi19abhi19 Member Posts: 9
    Yeah I did PM you about it.

    Where do I make the rules for the touched to 1, x to game.touch1.x, and y to game.touch.y?
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    you can create it anywhere, but i'd create another actor called detector that is 320x480. create the rules in that.
Sign In or Register to comment.