Jump with no gravity parabolic style

Hi guys,

Please help me with this.

I have a player.

I want to simulate him jumping (“parabolic style” - “U style”), and I want to achieve this with no gravity.

I tried this jump code (does not look very real).

local JUMP\_TIME = 500 transition.to ( player, { time = JUMP\_TIME, x = player.x + 100 ) transition.to ( player, { time = JUMP\_TIME / 2, y = player.y - 50, transition = easing.outQuad, onComplete = function () transition.to ( player, { time = JUMP\_TIME / 2, y = player.y + 50, transition = easing.inQuad ) end })

Do you have anything better/more intelligent?

Also, last question:

How to point my player jumping towards certain direction (let say for example he starts at centerX, centerY, and I want to point him at screenRight and screenTop (i.e. upper right part of the screen)?

Many many many thanks!!  :smiley:

G

The only thing I can think of that would be an alternate would be to do actual physics calculations of your own.  

The solution you show above should work fine however (after you tweak times and the use of easings).

Note: I say ‘fine’, but this will all be dependent upon the aesthetic you want/picture in your mind’s eye.

re: second question (bad practice to ask two questions in one post because they get missed)

Do you mean you want the jumping object (player) to face the direction of travel?  i.e. Tangent to arc?

If “yes”, you need to calculate that vector based on current and last position, convert the vector to an angle, and then set the rotation of the player based on that angle.

Question 1:
Ok Ed.
I will play around with the times some more! :slight_smile:

Question 2:
Yes.
Do you have one code example somewhere how to do that?

I will do one question at the time in the future! :slight_smile:

Many thanks!
G

Hi.  I didn’t have a lot of time to help on this, but… I have something, but there is an issue with it, so anyone out there who wants to look at it and help, please do:

https://www.youtube.com/watch?v=PcStYvJhIbs&feature=youtu.be

I think… that I’m calculating the acceleration, not the facing thus the arrow rotation seems to precede the actual movement.

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/06/facingMovmentDirection.zip

I found simple solution here:

https://forums.coronalabs.com/topic/41481-having-character-follow-finger-movement/

function updatePiranha ( event )     local deltaX = enemy.x - piranha.x     local deltaY = enemy.y - piranha.y     local piranhaDirection = math.atan2(deltaY, deltaX)          print("piranhaDirection = "..piranhaDirection)     print("piranhaDirection as degrees = "..math.deg(piranhaDirection))     piranha:setLinearVelocity( piranha.speed \* math.cos(1 \* piranhaDirection), piranha.speed \* math.sin( 1\* piranhaDirection))           end Runtime:addEventListener("enterFrame", update)

I just modified code by replacing touch event with object x and y  :smiley:

One problem left: I do not want to setLinearVelocity like showed above.

I want to use jumps by transition.to method…

I just have to figure out how to incorporate following code line into transition.to method…  :stuck_out_tongue:

piranha:setLinearVelocity( piranha.speed \* math.cos(1 \* piranhaDirection), piranha.speed \* math.sin( 1\* piranhaDirection))

Thanks!

G

Hi Ed,

I tried to implement this in transition.to, does not work!  :mellow:

It works like a charm when setting linear velocity like this:

piranha:setLinearVelocity( piranha.speed \* math.cos(1 \* piranhaDirection), piranha.speed \* math.sin( 1\* piranhaDirection))

But when doing this at transition.to:

– I have added 50 to speed transition up

transition.to{piranha, { time = 500, x = piranha.x + math.cos(1 * piranhaDirection) * 50 })  

transition.to{piranha, { time = 500, y = piranha.y + math.sin(1 * piranhaDirection) * 50 })

Simply does not work… sometimes player comes really close to the target, but does not proceed to the target…

I will keep trying, but no luck for now.

G

I will try the following.

  1. Create one invisible rect.
    Send it by linear steps :slight_smile:

  2. Follow jumps on that linear steps via transition.to.

I have nothing smarter :slight_smile:

Hi Ed,

Any idea how to store invisible moving rect x and y positions in a table {}?

And read those positions after?

I am getting errors when trying to do table.insert()…

That`s all…

Many many thanks.

G

re: storing x,y position of object in table

You can store the position of an object in a table, but when the object moves, those stored values won’t change.

-- Just an example, nothing I'd ever do unless I needed it for something... -- local tmp = display.newNewCircle( 10, 10 , 10 ) local tmp2 = {} tmp2.x = tmp.x tmp2.y = tmp.y local tmp3 = {} tmp3[#tmp3+1] = tmp2

You’d be better off storing a reference to the object in a table:

local tmp = display.newNewCircle( 10, 10 , 10 ) local objs = {} objs[tmp] = tmp -- .. later you can access all the objects you have stored in the table for k,v in pairs(obj) do print( v.x, v.y ) -- printing \<x,y\> position of each object in table. end

Note: This answer is a bit beyond the scope of your question and there are several things you need to be clear on for this to make sense, including objects scope, table indexing, object removal, proper cleanup…

Thanks Ed! :slight_smile:
I will try this.

I almost suceeed.

I have a problem that update function is called in Runtime.

And therefore before I cancell calling junpPlayer transition.to is called 5-6 times.
I cancell this with variable and if statement.

So basically Runtime is faster then changing variable from true to false…
That is my current problem.

G

I’m unclear on what you’re saying here, but I sense a confusion about things like:

  • ‘enterFrame’ listener (‘enterFrame’ is a Runtime event)
  • maybe touch listeners, if you are using them you may not be doing so correctly.
  • scope 
  • transition.to() and when it executes/updates versus your own code, as well as when onComplete occurs.

You’d be best off either:

  1. Posting a well formatted snippet of your code that is giving you trouble. 

  2. Posting all of your code on drop box or elsewhere and asking for community help reviewing it for issues.

I would do this (#2) as a new forum question and I’d give this synopsis:

a. what you’re trying to do (i.e. your goal)

b. what you’re seeing 

c. what you expect to see. 

Thanks Ed.

I opened new post here:

https://forums.coronalabs.com/topic/63751-jump-no-gravity/

G

The only thing I can think of that would be an alternate would be to do actual physics calculations of your own.  

The solution you show above should work fine however (after you tweak times and the use of easings).

Note: I say ‘fine’, but this will all be dependent upon the aesthetic you want/picture in your mind’s eye.

re: second question (bad practice to ask two questions in one post because they get missed)

Do you mean you want the jumping object (player) to face the direction of travel?  i.e. Tangent to arc?

If “yes”, you need to calculate that vector based on current and last position, convert the vector to an angle, and then set the rotation of the player based on that angle.

Question 1:
Ok Ed.
I will play around with the times some more! :slight_smile:

Question 2:
Yes.
Do you have one code example somewhere how to do that?

I will do one question at the time in the future! :slight_smile:

Many thanks!
G

Hi.  I didn’t have a lot of time to help on this, but… I have something, but there is an issue with it, so anyone out there who wants to look at it and help, please do:

https://www.youtube.com/watch?v=PcStYvJhIbs&feature=youtu.be

I think… that I’m calculating the acceleration, not the facing thus the arrow rotation seems to precede the actual movement.

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/06/facingMovmentDirection.zip

I found simple solution here:

https://forums.coronalabs.com/topic/41481-having-character-follow-finger-movement/

function updatePiranha ( event ) &nbsp;&nbsp;&nbsp;&nbsp;local deltaX = enemy.x - piranha.x &nbsp;&nbsp;&nbsp;&nbsp;local deltaY = enemy.y - piranha.y &nbsp;&nbsp;&nbsp;&nbsp;local piranhaDirection = math.atan2(deltaY, deltaX) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;print("piranhaDirection = "..piranhaDirection) &nbsp;&nbsp;&nbsp;&nbsp;print("piranhaDirection as degrees = "..math.deg(piranhaDirection)) &nbsp;&nbsp;&nbsp;&nbsp;piranha:setLinearVelocity( piranha.speed \* math.cos(1 \* piranhaDirection), piranha.speed \* math.sin( 1\* piranhaDirection)) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; end Runtime:addEventListener("enterFrame", update)

I just modified code by replacing touch event with object x and y  :smiley:

One problem left: I do not want to setLinearVelocity like showed above.

I want to use jumps by transition.to method…

I just have to figure out how to incorporate following code line into transition.to method…  :stuck_out_tongue:

piranha:setLinearVelocity( piranha.speed \* math.cos(1 \* piranhaDirection), piranha.speed \* math.sin( 1\* piranhaDirection))

Thanks!

G

Hi Ed,

I tried to implement this in transition.to, does not work!  :mellow:

It works like a charm when setting linear velocity like this:

piranha:setLinearVelocity( piranha.speed \* math.cos(1 \* piranhaDirection), piranha.speed \* math.sin( 1\* piranhaDirection))

But when doing this at transition.to:

– I have added 50 to speed transition up

transition.to{piranha, { time = 500, x = piranha.x + math.cos(1 * piranhaDirection) * 50 })  

transition.to{piranha, { time = 500, y = piranha.y + math.sin(1 * piranhaDirection) * 50 })

Simply does not work… sometimes player comes really close to the target, but does not proceed to the target…

I will keep trying, but no luck for now.

G

I will try the following.

  1. Create one invisible rect.
    Send it by linear steps :slight_smile:

  2. Follow jumps on that linear steps via transition.to.

I have nothing smarter :slight_smile:

Hi Ed,

Any idea how to store invisible moving rect x and y positions in a table {}?

And read those positions after?

I am getting errors when trying to do table.insert()…

That`s all…

Many many thanks.

G

re: storing x,y position of object in table

You can store the position of an object in a table, but when the object moves, those stored values won’t change.

-- Just an example, nothing I'd ever do unless I needed it for something... -- local tmp = display.newNewCircle( 10, 10 , 10 ) local tmp2 = {} tmp2.x = tmp.x tmp2.y = tmp.y local tmp3 = {} tmp3[#tmp3+1] = tmp2

You’d be better off storing a reference to the object in a table:

local tmp = display.newNewCircle( 10, 10 , 10 ) local objs = {} objs[tmp] = tmp -- .. later you can access all the objects you have stored in the table for k,v in pairs(obj) do print( v.x, v.y ) -- printing \<x,y\> position of each object in table. end

Note: This answer is a bit beyond the scope of your question and there are several things you need to be clear on for this to make sense, including objects scope, table indexing, object removal, proper cleanup…