I am using simi top camera where the whole screen is the ground for player to walk so i had to set the gravity to 0 otherwise my player would fall of the screen (or i am doing it wrong?). Now how do i make my character to jump?
Thanks in advance 
I am using simi top camera where the whole screen is the ground for player to walk so i had to set the gravity to 0 otherwise my player would fall of the screen (or i am doing it wrong?). Now how do i make my character to jump?
Thanks in advance 
Let me re-frame my question…
How do you perform jumps in situations when the whole background is a ground on which your player stands (thus you had to set gravity 0 to prevent your character from falling off the screen)?
Somebody please help!
You can manually transition your sprite to the new position.Â
Something like:Â
local player = create\_player () player.x, player.y = 100, 100 -- make a jump 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 })
Here, by joining 2 transitions at the same time (transition over x is linear, over y isn’t, so it gives you an illusion of parabolic movement - just like a jump forward in a constant gravity field) you get a jumping character without using physics. By modifying the x and y movement (100 and 50 here) you get different jumps.Â
I heard the transitions don’t perform physics and i need physics + collision detection 
Any workarounds?
Well, my guess is you can manually detect collisions (in some code you run every frame), checking the player’s object bounding rect vs other objects in his vicinity…Â
Hi @coolromin,
Just to clarify, collisions will trigger during a transition. However, the transition will continue to “fight” against any opposing physical force caused by the collision (like a bounce off in the other direction), so you’d need to cancel the transition at that point to prevent weird behavior.
Best regards,
Brent
There is no workaround to use normal physics to jump the player??? :0
Well, one solution would be to use normal gravity, but then set your “zero gravity” objects to have a gravity scale of 0. This way, they would float in air, while the player would jump and be affected by gravity as normal.
http://docs.coronalabs.com/api/type/Body/gravityScale.html
Brent
Finally seems like a working solution… But i am very new to corona and so little confused with the solution you provided.
Can you please show me a sample code on how to implement it? Thanks in advance!
I set the gravityScale to 1 and applied linear velocity, The player jumps and falls down but keeps falling down so how do i stop him at same position it was before?
Thanks Again!
I think you’ll need to place a static block at the bottom of the screen.
Have you tried something like this?
[lua]
local bottom = display.newRect( 0, 0, display.contentWidth, 100 )
bottom.x = 0
bottom.y = display.contentHeight + ( bottom.height * .5 )
physics.addBody( bottom, “static” )
[/lua]
Let me re-frame my question…
How do you perform jumps in situations when the whole background is a ground on which your player stands (thus you had to set gravity 0 to prevent your character from falling off the screen)?
Somebody please help!
You can manually transition your sprite to the new position.Â
Something like:Â
local player = create\_player () player.x, player.y = 100, 100 -- make a jump 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 })
Here, by joining 2 transitions at the same time (transition over x is linear, over y isn’t, so it gives you an illusion of parabolic movement - just like a jump forward in a constant gravity field) you get a jumping character without using physics. By modifying the x and y movement (100 and 50 here) you get different jumps.Â
I heard the transitions don’t perform physics and i need physics + collision detection 
Any workarounds?
Well, my guess is you can manually detect collisions (in some code you run every frame), checking the player’s object bounding rect vs other objects in his vicinity…Â
Hi @coolromin,
Just to clarify, collisions will trigger during a transition. However, the transition will continue to “fight” against any opposing physical force caused by the collision (like a bounce off in the other direction), so you’d need to cancel the transition at that point to prevent weird behavior.
Best regards,
Brent
There is no workaround to use normal physics to jump the player??? :0
Well, one solution would be to use normal gravity, but then set your “zero gravity” objects to have a gravity scale of 0. This way, they would float in air, while the player would jump and be affected by gravity as normal.
http://docs.coronalabs.com/api/type/Body/gravityScale.html
Brent
Finally seems like a working solution… But i am very new to corona and so little confused with the solution you provided.
Can you please show me a sample code on how to implement it? Thanks in advance!
I set the gravityScale to 1 and applied linear velocity, The player jumps and falls down but keeps falling down so how do i stop him at same position it was before?
Thanks Again!