Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Trying to program a good jump...
Started by mgaston927 Apr 07 2017 03:27 PM

8 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

mgaston927

[GLOBAL: userInfoPane.html]
mgaston927
  • Observer

  • 7 posts
  • Corona SDK

I'm making a game about a frog and I'm having trouble making his jump look/feel right. Here's the code:

function jump( event )

	if ( canJump == true ) then
		canJump = false
		frog:applyLinearImpulse( 0, -15, frog.x, frog.y )
		vx, vy = frog:getLinearVelocity()
		gx, gy = physics.getGravity()

		local result = 2 * -vy / gy
		print(result)
		
	end

But the result I'm getting is about 51 seconds, even though the frog is only off the ground for about 1 second. How can I find the amount of time the frog is actually in the air?



[TOPIC: post.html]
#2

sdktester15

[GLOBAL: userInfoPane.html]
sdktester15
  • Contributor

  • 999 posts
  • Corona SDK

It could be a problem of how you wrote the equation:

 

It could be doing this:

(2 * -vy) / gy

Or this: 

2 * (-vy / gy)

Try switching the orders of the variables in the equation around and see if you get a more accurate answer.



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 4,680 posts
  • Enterprise

I'm not sure I understand the question or the intent of that code.

 

The units for gravity and velocity in the real world are not the same.

 

Metric Velocity ==> Meters Per Second (m/s)

 

Metric Gravity (Acceleration) ==> Meters Per Second Squared  (m/s^2)

 

 

Also, please define "Feels Right".   Does

 

"Feels Right" == "Super Mario Brothers" 

 

- OR - 

 

"Feels Right" == "Like the Real World"

 

If the answer is "Super Mario Brothers" that is a very elaborate jump algorithm, not just a single impulse and gravity combination.


Edited by roaminggamer, 07 April 2017 - 05:21 PM.


[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 4,680 posts
  • Enterprise

You might enjoy this video:

 



[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 4,680 posts
  • Enterprise

If you want something approximating a real world arc, it is pretty straight-forward:

physics.getGravity( 0, 9.8 )

local jumpMagnitude = -15


function jump( event )
   if ( canJump == true ) then
      canJump = false
      frog:applyLinearImpulse( 0, jumpMagnitude  * frog.mass , frog.x, frog.y )
   end
end


[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 4,680 posts
  • Enterprise

Also, be aware that getting the velocity directly after an impulse may not 'get' the entire velocity of the impulse.  It may simply get the velocity at the time 't' when the impulse will be applied.

 

I haven't verified this, but my sense is this is true.

 

If someone has tested this and I am wrong, please correct me here.



[TOPIC: post.html]
#7

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 4,680 posts
  • Enterprise

Try this example I wrote up: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/04/betterjump.zip

 

 

 

Bottom character gets increased gravity scale as soon as 'jump touch' is released.  Gravity scale is increased via transition.

 

In the video:

  • First series of jumps, I hold touch to show jumps are same.
  • Second series of jumps, I release early and the gravity scale logic kicks in for bottom player.


[TOPIC: post.html]
#8

mgaston927

[GLOBAL: userInfoPane.html]
mgaston927
  • Observer

  • 7 posts
  • Corona SDK

It could be a problem of how you wrote the equation:

 

It could be doing this:

(2 * -vy) / gy

Or this: 

2 * (-vy / gy)

Try switching the orders of the variables in the equation around and see if you get a more accurate answer.

 

Can confirm, result does not change.



[TOPIC: post.html]
#9

mgaston927

[GLOBAL: userInfoPane.html]
mgaston927
  • Observer

  • 7 posts
  • Corona SDK

I'm not sure I understand the question or the intent of that code.

 

The units for gravity and velocity in the real world are not the same.

 

Metric Velocity ==> Meters Per Second (m/s)

 

Metric Gravity (Acceleration) ==> Meters Per Second Squared  (m/s^2)

 

 

Also, please define "Feels Right".   Does

 

"Feels Right" == "Super Mario Brothers" 

 

- OR - 

 

"Feels Right" == "Like the Real World"

 

If the answer is "Super Mario Brothers" that is a very elaborate jump algorithm, not just a single impulse and gravity combination.

 

To clarify, I'm trying to calculate the duration of a jump for any given impulse and gravity value. As for the feeling, I'd like it to be realistic.




[topic_controls]
[/topic_controls]