Two Actions For One Attribute
Hi there. I am working on a project where I have a ninja that flies in midair. So, I use a trajectory parabola. I use this rule to create the movement.
If Mouse Button is UP:
Change Velocity
Direction: game.Launch Angle
Speed: game.Launch Velocity
Accelerate (for gravity)
Direction: 270
Speed: 100
When mouse is down:
Spawn the trajectory dots
In short, I tap and drag to move the dots and make the arc, and release to let the ninja fly. What I want to accomplish is that only when the ninja is in midair and moving, the user is able to tap to throw a shuriken, without spawning the dots, and can release changing the path of movement.
How would I go about doing this?
P.S. I can upload the project file if needed… (I think :P)
If Mouse Button is UP:
Change Velocity
Direction: game.Launch Angle
Speed: game.Launch Velocity
Accelerate (for gravity)
Direction: 270
Speed: 100
When mouse is down:
Spawn the trajectory dots
In short, I tap and drag to move the dots and make the arc, and release to let the ninja fly. What I want to accomplish is that only when the ninja is in midair and moving, the user is able to tap to throw a shuriken, without spawning the dots, and can release changing the path of movement.
How would I go about doing this?
P.S. I can upload the project file if needed… (I think :P)
Comments
When the ninja is launched, set ninjaFlying to 1
When the ninja lands, set ninjaFlying to 0
(For dot spawning)
When all:
ninjaFlying = 0
touch is pressed
----spawn dots
(For shuriken throwing)
When all:
ninjaFlying = 1
touch is pressed
----spawn shuriken
If I put a condition under my movement rule where flying has to equal 0, it isn't able to process the fact that it has gravity on it.
(For ninja launching)
When all:
attribute: ninjaFlying is 0
actor receives event: mousebutton is up
----change velocity
----accelerate
P.S. It does take away midair movement, which is good! :P
I can't find any comments about something going "way too fast". What is that about?
Ok -- how about a different idea? Instead of an accelerate behavior, can you just set the ninja's Y velocity to game.gravity. (Untested -- just a wild idea.)
EDIT: This is what happens when I use scene gravity:
http://tinypic.com/r/161cp41/7
I really can't think of any reason that setting an integer attribute would stop an acceleration behavior from firing. There must be some logic error. Can give some detail about how the rule and its behaviors are currently set up?
http://tinypic.com/r/wwcls8/7
Hint: Click the magnifying glass in the bottom right...
I think that scene gravity worked well apart from the random bouncing. Actually, it wasn't random, it was just using the mouse's direction and distance, but I have no idea why it wasn't stopping.
Any ideas?
How about this. The only time you want the ninja to move is when flying = 1 -- so try changing the rule to this:
When all
----attribute flying is 0
----mouse button is down
--------change attribute: flying To: 1
Then a new rule:
When
----attribute flying is 1
--------change velocity
--------accelerate
--------When
------------mouse is up (or down or whatever)
----------------spawn shuriken
And a new rule for hitting the ground and stopping the ninja from flying.
When
---- actor overlaps or collides with actor of type floor
--------change attribute: flying To: 0
--------change anything else to reset the ninja
BTW: In the first rule, I changed mouse down to mouse up.
Also, it looks to me like there is still an error with the accelerate behavior. It overpowers everything. I'm learning from this to be cautious about using accelerate.
But on the bright side -- the question for this thread has been answered -- right?? The ninja now jumps and can throw a shuriken -- both with a tap?
Then use either 'move to' or 'change velocity' or 'accelerate toward' or 'change attribute' to get the shuriken to move where you want it to go.
Once it gets to the place you send it, then either destroy it or change its x,y position to somewhere hidden off-scene.
When flying = 1
mouse is up
spawn shuriken self.position.x self.position.y
And in the shuriken make a rule
when flying = 1
mouse is up
accelerate vectortoangle(mouseX,mouseY)
Am I understanding right?
(In the shuriken).
Then after the shuriken hits something, or exits the scene -- destroy actor.
I was thinking of just setting an attribute to the mouse clicks, but if the user rapid fires, it will be all messed up…
Any ideas? :P
Each click will spawn a new shuriken. And each shuriken will chase the mouse.
Once it hits the mouse the actor stops so keep the mouse moving. (Or destroy the actor on mouse collision.)
Thanks! :P