Jump no gravity

Hi all!  :smiley:

I am trying to make a game where red player jumps towards target (blue color).

You can see attached screenshot here:

https://www.dropbox.com/s/3hm2f6yifjlvz8x/Game.png?dl=0

In this sketch player uses 3 jumps in total, but that could be 4-5-6-7 jumps depending on a distance between them. Red circles with white color are just points where player would jump (just for illustration).

So far I have this code:

local player = display.newCircle( 0, 0, 25 ) player:setFillColor(1, 1, 1) player.x = screenWidth\*0.1 player.y = math.random(screenHeight\*0.25, screenHeight\*0.85) player.isFixedRotation = true local blueTarget = display.newCircle( 0, 0, 25 ) blueTarget:setFillColor(1, 1, 1) blueTarget.x = screenWidth\*0.8 blueTarget.y = math.random(screenHeight\*0.25, screenHeight\*0.85) blueTarget.isFixedRotation = true function jumpPlayer() local jumpTime = 500          transition.to ( player,  { time = jumpTime, x = player.x + player.width\*2 } )          transition.to ( player, { time = jumpTime/2, y=player.y - player.height\*2, transition = easing.outQuad,        onComplete = function()         transition.to ( player, {time = jumpTime/2, y = player.y - player.height, transition = easing.inQuad })          end }  ) end

I can calculate distance between red circle and blue circle like this:

local distance = math.sqrt ( (blueTarget.x - player.x)^2 + (blueTarget.y - player.y)^2)

I can calculate direction like this:

local deltaX = blueTarget.x - player.x local deltaY = blueTarget.y - player.y local Direction = math.atan2(deltaY, deltaX) \* 180 / math.pi

Can you please help me how to accomplish these jumps?

These jumps are not controlled by people who play the game, jumps should be “guided” like missile!   :smiley:

Waiting your reply!!

Thanks!

G

Is your “gravity” straight down, or at angle as in the picture?

Depending on your needs, you might be able to model this as a projectile, e.g. see here, and in particular " Height at x".

Also, related to the enterFrame stuff you mentioned in the other thread, maybe you can take advantage of Lua’s metatables and transition a dummy variable such as time. See for example this thread.

Hi StarCrunch.
Thanks for your input.

No gravity force on the player, as title says: “No gravity jump”.

So no trajectories… only transitions or something smarter.

Well, I did put it in quotes.  :) From your image, I wasn’t quite sure if the character(the piranha?) would be jumping up platforms, or forward while being viewed at an angle, etc, so I was wondering about that.

In the end, trajectories are just equations, with “g” simply the acceleration of the curve, so you can certainly evaluate them without using physics. (And these are as parabolic as it gets!) The link in my last paragraph suggests one way to tie them to transitions.

It is not that simple to draw 3 trajectories for 3 jumps, and to tie them with transition.to
No platforms in this game :slight_smile:

If nobody comes with smarter solution, I will solve this sending invisible scout by direct line.

I am calling it follower.

local deltaX = blueTarget.x - follower.x local deltaY = blueTarget.y - follower.y local Direction = math.atan2(deltaY, deltaX) \* 180 / math.pi local distance = math.sqrt ( (blueTarget.x - follower.x)^2 + (blueTarget.y - follower.y)^2) follower:setLinearVelocity( 200\*math.cos(1 \* Direction ), 200\*math.sin( 1\* Direction))

And I will jump on follower x and y with certain paste  :smiley:

The only problem I am facing, is that some times follower stops before reaching target if speed factor is too high (200 in this case). If speed factor is low, lets say 50, then follower never stops (always reaches the target).

But I want high speed factors  :D  :wub:

Is your “gravity” straight down, or at angle as in the picture?

Depending on your needs, you might be able to model this as a projectile, e.g. see here, and in particular " Height at x".

Also, related to the enterFrame stuff you mentioned in the other thread, maybe you can take advantage of Lua’s metatables and transition a dummy variable such as time. See for example this thread.

Hi StarCrunch.
Thanks for your input.

No gravity force on the player, as title says: “No gravity jump”.

So no trajectories… only transitions or something smarter.

Well, I did put it in quotes.  :) From your image, I wasn’t quite sure if the character(the piranha?) would be jumping up platforms, or forward while being viewed at an angle, etc, so I was wondering about that.

In the end, trajectories are just equations, with “g” simply the acceleration of the curve, so you can certainly evaluate them without using physics. (And these are as parabolic as it gets!) The link in my last paragraph suggests one way to tie them to transitions.

It is not that simple to draw 3 trajectories for 3 jumps, and to tie them with transition.to
No platforms in this game :slight_smile:

If nobody comes with smarter solution, I will solve this sending invisible scout by direct line.

I am calling it follower.

local deltaX = blueTarget.x - follower.x local deltaY = blueTarget.y - follower.y local Direction = math.atan2(deltaY, deltaX) \* 180 / math.pi local distance = math.sqrt ( (blueTarget.x - follower.x)^2 + (blueTarget.y - follower.y)^2) follower:setLinearVelocity( 200\*math.cos(1 \* Direction ), 200\*math.sin( 1\* Direction))

And I will jump on follower x and y with certain paste  :smiley:

The only problem I am facing, is that some times follower stops before reaching target if speed factor is too high (200 in this case). If speed factor is low, lets say 50, then follower never stops (always reaches the target).

But I want high speed factors  :D  :wub: