Touch to fire
Portgas
Member Posts: 71
I have no idea how to make "gun" shoot in specific place where i tap on screen (click mouse button)
can anyone help me with this? tried to understand something from demos but i cant make my gun shoot at all(
can anyone help me with this? tried to understand something from demos but i cant make my gun shoot at all(
Comments
When actor receives event 'mouse button' is 'down'
Then drag in behaviour:
Spawn actor:
Then select your bullet actor.
For the position, set it as mouse.position.X for the 1st box,and mouse.position.Y for the second box and set it to 'relative to scene' in the last box. That should work.
Chobbipod
To make the bullet spawn at the point of the gun AND go to where you touch, do something like:
In the gun ->
when screen is touched then game.where = vectorToAngle(gun.x-mouse.x, gun.y-mouse.y), spawn bullet at gun.x, gun.y .
In the bullet -> changeVelocity to game.where .
And that should do it. Don't set a move, or else the direction of the bullet will change when you touch another spot, the changeVelocity should fire just once, using the angle of the vector between the gun and the touch to set himself a direction where to travel.
Chobbipod
I lost the habit to save every 5 seconds.
create actors called bullet and trigger, bullet sized 10x10 and trigger the size of the window, so 480x320
create two global attributes, touchX and touchY
on the trigger actor have a rule that says
when actor receives touch
set game.touchx to touch.position.x
set game.touchy to touch.position.y
spawn bullet at position 0,0 relative to scene
on the bullet create two new attributes called X and Y
then put a few rules:
change attribute self.X to game.touchX
change attribute selft.Y to game.touchY
moveto self.X, self.Y
this way, every time you touch the point is recorded, when a bullet is spawned it saves a local copy of that point and moves to it from the lower left of the screen, you can click multiple times and each one will go to it's own point.
but do a search, there are a TON of threads on this, and there might be better ways than mine.
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
Just some blank square, but it should help anyway.
Basically it's done with just one game.variable, a rule, a change attribute, a spawn. And a change velocity in the bullets. That's it.
I added a way to get a delay between a shot and the other, that means that you can't shoot 100 bullets in 1 sec if I don't want you too. Just change the variable delayBetweenBullets in the gun to raise up or low the delay.
Since gamesalad didn't let me upload it, I uploaded the gameproj to megaupload
http://www.megaupload.com/?d=S4LGZNYA