How to determine how high to jump using swipe?

Hi Hello,

I was playing around with @StormyStudio‌ template about orbiting and jumping. What I am trying to achieve is that you have to touch and swipe it forward and up to jump. But the faster the swipe the fast and higher the jump will be. At the moment I have tried using Magnitude to determine a height and recognise a swipe but its a constant speed and doesn't look great.

The effect I am looking for is the affect you would get on angry birds Space if you touch and flicked the bird rather than using a slingshot.

What direction should I be taking with this one?

Comments

  • osakamitsuosakamitsu Member Posts: 70

    Im still new to GS so my contribution may be useless but I think it may have something to do with linear velocity? Hope I am at least close... :D

  • UtopianGamesUtopianGames Member Posts: 5,692
    edited July 2014

    You would need to determine the speed of the swipe by using a game integer and do…

    Constrain Game.Speed to magnitude( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y )

    If your constraining your actor to the mouse it won't work but theres a way around that by using…

    Constrain Motion.Linear Velocity.X to 20*( game.Mouse.Position.X - self.Position.X )

    Constrain Motion.Linear Velocity.Y to 20*( game.Mouse.Position.Y - self.Position.Y )

    Change the 20 to suit…higher the number the faster the actor will react.

    Darren.

  • CodeCellCodeCell Member Posts: 90

    @DeepBlueApps said:
    You would need to determine the speed of the swipe by using a game integer and do…

    Constrain Game.Speed to magnitude( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y )

    If your constraining your actor to the mouse it won't work but theres a way around that by using…

    Constrain Motion.Linear Velocity.X to 20*( game.Mouse.Position.X - self.Position.X )

    Constrain Motion.Linear Velocity.Y to 20*( game.Mouse.Position.Y - self.Position.Y )

    Change the 20 to suit…higher the number the faster the actor will react.

    Darren.

    That's works just if an actor is stationary. However the actor is rotating around in a circle.
    And to do this it is only constraining its position and rotation to the centre of its rotation., such as the centre of the screen, which would mean there is no to adjust the speed that it's travelling around the circle. Thank you :)

    It means I going to , or if anyone knows away, research away where I can control the speed it's travelling around. This may be more complicated than I thought. Time to bring out those big complex maths books.

    @osakamitsu said:
    Im still new to GS so my contribution may be useless but I think it may have something to do with linear velocity? Hope I am at least close... :D

    Nothing is ever useless, it's only useless if it's not said. Thanks, I been playing around with it, like Darren has said. But it means I need to find a new way to calculate the speed for the actor rotating.

  • ArmellineArmelline Member, PRO Posts: 5,369

    Okay, if I'm understanding you correctly, you're using @StormyStudio's planet hop template, and are wanting to make it so a swipe causes the jump, and the speed of the swipe dictates the speed and height of the jump?

    Having just taken a look at the template, it seems the jump is controlled by an interpolate. This makes it, assuming I've understood correctly, really quite simple.

    As such, changing the speed should be pretty simple.

    1. Make a touch area that covers the screen (or whatever area you want them to be able to swipe in).
    2. When touch is pressed, record the starting position of the touch (for this example stored in game.TouchX and game.TouchY) and the starting time (game.TouchStart).
    3. When touch is released, record the ending position (game.ReleaseX and game.ReleaseY) and the ending time (game.TouchEnd).
    4. Also in the touch is released, calculate the distance of the swipe (magnitude(game.StartX-game.EndX,game.StartY-game.EndY)).
    5. Also in the touch is released, calculate the duration of the swipe (game.TouchEnd-game.TouchStart).
    6. You now have the distance and the time, so speed is one super-simple equation away. (game.Distance/game.Duration).
    7. Once you have the speed and the distance of the swipe, you can use them to adjust the interpolate duration and the interpolate distance.

    Assuming I'm understanding what you're asking, and it's very much possible I'm not :smiley:

  • CodeCellCodeCell Member Posts: 90

    @‌Armelline

    Velocity equals speed /time. That part was simple. Yes it is the planet and actor rotating around.
    However the swipe's direction should alter the direction of the jump. Hopefully the below image can explain it easier:

    http://www.mediafire.com/view/3gx549ga61vxevu/Swipe_1.png

    (Don't know how to make it show up, seem to be having issues with internet)

    As the image shows, a swipe at a 45 degrees would have a different effect to 180 degree swipe, same applies for swipe speed, the smaller the radius zone would be. I have a feeling it involves maths formulas.

  • ArmellineArmelline Member, PRO Posts: 5,369

    Unfortunately I can't get that image to load, but based on what you said, the only addition you need to my previous post is to calculate the direction of the swipe, which is fairly simple. I'll throw together an example file shortly (I have one 2/3 made somewhere anyhow). Working out if a swipe is up/down/left/right is just a matter of a tiny bit of simple maths, but it does get a little more complicated when you want to take into account diagonals, or precise angles. Still very much possible though.

Sign In or Register to comment.