How to spawn actor in direction of mouse
abhi19
Member Posts: 9
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.
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
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.
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
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?
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
Where do I make the rules for the touched to 1, x to game.touch1.x, and y to game.touch.y?
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left