Two Actions For One Attribute

ChessPawnChessPawn Member Posts: 127
edited November -1 in Working with GS (Mac)
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)
«1

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Have a global attribute called something like "ninjaFlying" or whatever. Make it an integer attribute.

    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
  • ChessPawnChessPawn Member Posts: 127
    That works, but the ninja still flies around in midair when tapped. I mean like, not in a set path, but if moving and tapped, it'll fly in that direction.

    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.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Do you have both the change velocity and the accelerate behaviors within the same rule? And does the rule have 'when all' set?

    (For ninja launching)
    When all:
    attribute: ninjaFlying is 0
    actor receives event: mousebutton is up
    ----change velocity
    ----accelerate
  • ChessPawnChessPawn Member Posts: 127
    But then where do I put change flying to 1, so as to stop change of movement in midair? If I put it in the movement rule, it never processes the gravity.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    ChessPawn said:
    But then where do I put change flying to 1, so as to stop change of movement in midair? If I put it in the movement rule, it never processes the gravity.

    Oh... um... well... How about putting the 'change flying to 1' at the very end of the rule. That way everything gets modified (including accelerate to 270 -- gravity) before the boolean gets changed?
  • ChessPawnChessPawn Member Posts: 127
    Nope. No dice. It just goes way too fast. What I noticed was that you are using when touch is pressed in your example. I am using when mouse is down. Is that the problem?

    P.S. It does take away midair movement, which is good! :P
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Great! This fix was supposed to take away the "movement in midair". And that's all.

    I can't find any comments about something going "way too fast". What is that about?
  • ChessPawnChessPawn Member Posts: 127
    I don't know why I wrote "too fast." What I mean is that, it still doesn't recognize the gravity. Maybe I meant it switches the attribute too fast for the gravity. :P
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    ChessPawn said:Maybe I meant it switches the attribute too fast for the gravity. :P

    OK -- how about putting a timer between the "accelerate to 270" and the "change flying to 1". See if slowing it down between the two behaviors helps. Make it something like .5 seconds and then work on shortening the timer to its minimum before it starts to mess with the acceleration behavior.
  • ChessPawnChessPawn Member Posts: 127
    Already tried that, and by the time it gets to gravity, it's been like 2 seconds. My only other thought would be setting gravity on the whole scene.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Doesn't it sound strange that setting one integer attribute (flying) is causing an accelerate behavior not to fire?

    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.)
  • ChessPawnChessPawn Member Posts: 127
    How would I go about doing that. If you mean constrain attribute linear velocity y to game.gravity, it didn't work… :P

    EDIT: This is what happens when I use scene gravity:

    http://tinypic.com/r/161cp41/7
  • ChessPawnChessPawn Member Posts: 127
    BUMP: Anybody know how or why?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Hey! The video looks interesting. Perhaps you can incorporate it into the game somehow. Make it a selling point. Perhaps something like "Who needs boring predictable ninjas? This game has super intelligent jumping ninjas that are so smart you won't be able to predict where they will go!"

    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?
  • ChessPawnChessPawn Member Posts: 127
    Hopefully you can see the video:

    http://tinypic.com/r/wwcls8/7

    Hint: Click the magnifying glass in the bottom right...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Yes -- I was able to replicate the same thing that is happening. My guess is that the accelerate behavior starts the acceleration process, but then is interrupted because the rule is no longer valid. (Maybe that is why its described as a 'persistent behavior', rather than an 'action'. But the behavior only persists as long as the rule associated with it is valid.)
  • ChessPawnChessPawn Member Posts: 127
    Ya so the accelerate is just a simulation of gravity, but because ninjaFlying is switched to 1 before the accelerate can be processed it doesn't work, as the mouse needs to be up and ninjaFlying=0.

    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?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- trying to think of why this logic error is happening.

    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
  • ChessPawnChessPawn Member Posts: 127
    Why does it not change the attribute to 0 when I hit the block?

    BTW: In the first rule, I changed mouse down to mouse up.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    I did a search for problems using collide in a rule -- it seems there is a bug in there. The collide rule seems to have problems.

    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?
  • ChessPawnChessPawn Member Posts: 127
    It can, but how would I make it look like it's "throwing a shuriken"? Like accelerating from the center of the ninja towards the edge of the screen. Right now it just makes a shuriken where I click…
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Either spawn the shuriken or (if it is already hidden off-scene) move it to the x,y of the ninja. (Instead of the x,y of the mouse.)

    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.
  • ChessPawnChessPawn Member Posts: 127
    If I understand what you're saying, you mean in the ninja make a rule

    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?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Yes-- but I don't think you need to make a rule in the shuriken, do you? Couldn't you just use a move to, or accelerate to, or change velocity to get the actor moving toward the mouse click, or any other point or angle that it needs to.
  • ChessPawnChessPawn Member Posts: 127
    It can only fire to the right, and not to the left. I am using change velocity under the shuriken, no rule and vectortoangle(mouseX,mouseY). Any ideas?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    How about using accelerate toward: mouseX, mouseY, scene
    (In the shuriken).

    Then after the shuriken hits something, or exits the scene -- destroy actor.
  • ChessPawnChessPawn Member Posts: 127
    In this situation, the shurikens fly in the air, literally following the mouse!

    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
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- in the shuriken, have a single Move To: mouse.x, mouse.y, scene.

    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.)
  • ChessPawnChessPawn Member Posts: 127
    I'll try that in the morning, but in the end, I just want it to either keep moving off screen, or collide with an enemy and then destroy itself.

    Thanks! :P
  • ChessPawnChessPawn Member Posts: 127
    Is it not possible to get them to just shoot in a straight line depending on where the user tapped?
Sign In or Register to comment.