How do you make an actor react in a parabolic fashion against gravity?

I'm wanting to shoot an actor upwards in the air at say 75 degrees then slowly rotate to downwards of 25 degrees as gravity overcomes the upwards acceleration a bit like a parabolic curve is there anyway to do this?

Kind Regards

John

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Hi John, there are probably a bunch of different ways to do what you are asking. One way is to give your actor these behaviors:

    Accelerate, direction 270, acceleration 300 (or whatever fits your game), relative to screen. (This will act as gravity on the actor, you could also use the overall scene gravity but I prefer this method).

    Then when some condition is met, maybe pressing a key. Use:

    Change Velocity, direction 75, speed 300 (or again whatever fits your game), Relative to scene.

    Thats' one way.
  • CoolBeeCoolBee Member Posts: 81
    Hi @jamie_c I've just tried the velocity and nothing happen, is there something else I should be adding?
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    @CoolBee, here is a demo project. Press the spacebar and the object will hop into the air and move back down in an arc. Hope this is the kind of motion you're looking for.
  • CoolBeeCoolBee Member Posts: 81
    @jamie_c hiya thanks for that but thats not it it's only the rotation of the actor is what I'm after, like if you imagine a plane taking off nose up(when the space bar is pressed) then nose down when the plane is falling/nose diving if you get me?
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Oh I see, you could probably use the Rotate to Angle behavior for something like that. Like when your actor is moving up Rotate to a certain angle and when your actor is moving down rotate to another angle...
  • CoolBeeCoolBee Member Posts: 81
    edited June 2013
    Right thanks @jamie_c would that go something like, game.hero.positionY - game.hero.positionY+1 then change angle to 70, then the same for down only -1 instead?
  • ORBZORBZ Member Posts: 1,304
    if you simply want to change the direction the actor is facing as it falls use this:

    constrain actor.rotation = vectorToAngle(actor.linearVelocityX, actor.linearVelocityY)
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    I've attached an update to the demo, check out scene 2. Use the arrow keys to move the actor up and down. I'm not sure if this is what you need. If not maybe you can do a drawing of what you are trying to accomplish exactly?
  • CoolBeeCoolBee Member Posts: 81
    Thanks @jamie_c its kind of that but needs to react on its own to gravity, @ORBZ I've just tried that and i must not know enough about it since its the first time I've used it so am experiencing wildly varying results could you possibly give me a demo or something?
  • ORBZORBZ Member Posts: 1,304
    edited June 2013
    @CoolBee

    If your actor is moving based on physics - i.e. it's moved because something else bumped it or because it's using the Change Velocity or Accelerate or gravity behaviors do this:

    Inside the actor add the following line:

    Constrain Attribute self.rotation = vectorToAngle(self.motion.linearVelocityX, self.motion.linearVelocityY)

    This presumes your actor "front" is facing right by default, i.e. 0 degrees.

  • CoolBeeCoolBee Member Posts: 81
    @ORBZ right I've added that but as soon as I press the space bar(jump) the actor changes to 1 of his flap images then doesn't change?
  • ORBZORBZ Member Posts: 1,304
    changing images isn't really the same thing as changing direction.

    i'm going to upload an example... one sec.
  • ORBZORBZ Member Posts: 1,304
    @CoolBee

    Attached is an example project that shows what i'm talking about.
  • CoolBeeCoolBee Member Posts: 81
    Ahaa I see what you mean, @ORBZ Now I see how the smooth up/drop action works but my actor is in a fixed position on the screen with a moving background/objects to create the illusion of movement (trying to fly as far as possible with a limited number of flaps) each flap increases him in Y,

    Now I've tried to move over the rules from your scene but I can't replicate it while keeping him in the same position, Sorry for all the trouble btw!
  • ORBZORBZ Member Posts: 1,304
    Ohh! I didn't understand that he stays in the same position. In that case what I wrote won't apply at all since you don't actually have any motion.

    In that case you need to have your actor face in whatever direction the background is scrolling + 180 degrees.
  • CoolBeeCoolBee Member Posts: 81
    Oh right haha :) well he's facing in the direction he wants to go in but what rule should i use/put the 180 degrees in? @ORBZ
  • ORBZORBZ Member Posts: 1,304
    It's not a rule, it's a constraint. Calculate the angle that the scene is moving at and then constrain the actors.rotation to the calculated angle + 180
  • CoolBeeCoolBee Member Posts: 81
    @ORBZ Seems I have further failed! not only does it not work how I want it to but the actor goes nuts while on the ground do you mind if you would take a look at it and see where I'm going wrong? Ill pm you the drop box
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited June 2013
    Okay so I think I get what you're after. Basically sounds like you have a bird or something you need to flap to get it to rise on the Y axis and you're using a parallax background so the bird doesn't actually move on the X axis. So you are probably using some kind of velocity trigger to make it rise. So let's say just for example it takes a velocity of >100 to make him go up. So if you put your actor in correctly his front should face to the right of the actor when you made it. The far right edge of the actor at the half point of the height is 0deg in GS. You can tell what is 0 on an actor by selecting it and where the handle to rotate it sticks out that is 0.

    If I'm right this will work.

    Rule

    If attribute self.linear.velocity.Y > 100

    Change attribute self.rotation to 25

    Rule

    If attribute self.linear.velocity. Y < 100

    Change attribute self.rotation to 340

    So if it takes a velocity of 100 or higher to make him go up the bird will face up a bit and when the velocity falls below 100 he drops and the bird will face down. This should get you thinking of ways to do it.
  • ORBZORBZ Member Posts: 1,304
    edited June 2013
    @CoolBee

    If what @FryingBaconStudios is saying is correct - namely that you're actor moves up and down based on LinearVelocityY but doesn't move left or right and instead the background moves left and right - Then what he said will work. However, here is a simpler and more precise method that doesn't need as many rules and tilts more as the bird travels up/down faster and less as the bird travels up/down slower. This will create the illusion of a perfect parabolic arc even though you are not actually moving.

    Inside the bird actor do this:

    Define tiltDegreesMax = 45 (set this to whatever looks best for you)
    Constrain self.rotation = self.linearVelocityY / self.maxVelocity * self.tiltDegreesMax
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Ah Thanx @ORBZ I'm not so good at the vector math..haha
  • CoolBeeCoolBee Member Posts: 81
    Tbh you both just blew my mind with velocity maths!! :) @ORBZ @FryingBaconStudios
  • ORBZORBZ Member Posts: 1,304
    I whipped up this example because I wanted to see how it would look.

  • CoolBeeCoolBee Member Posts: 81
    @ORBZ Interesting! Thanks for your help guys, some of these demo are amazing orbs! and give me real interest in what is achievable in GS
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Yes remember don't let your mind get blocked by the GUI interface of GS try to thing in terms of logic and what is really going on. Coding is all just about monitoring and changing variables and conditions. So think about that not the behaviors. The behaviors are only a window to enter in the info and tell the computer how to adjust the info or look to see what the current info is at any point or watch for when the info changes or is a specific number or whatever.
  • ORBZORBZ Member Posts: 1,304
    @FryingBaconStudios

    "Coding is all just about monitoring and changing variables and conditions."

    Check out functional programming then -- it's most certainly not like that. ;)

    http://en.wikipedia.org/wiki/Functional_programming

    GS is a form of event driven programming

    http://en.wikipedia.org/wiki/Event-driven_programming
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Ah sorry @ORBZ I was referring to GS coding...lol
  • CoolBeeCoolBee Member Posts: 81
    Cheers tho guys much appreciated :)
Sign In or Register to comment.