Player Jumping

Hey guys, I’m new here. I’ve been learning Corona for the past few days and today I found a way to make a character jump. The problem I’m having is that the character seems to “glide.” As in, he slowly moves upward until reaching the peak, and then slowly starts to fall back down. Is there a way to remove the “glide”? I’ve tried adjusting the density of the player and the vspd variable, but it doesn’t seem to do much. Here’s the code I am currently using:

[lua]
local physics = require(“physics”)
physics.start()

local ground = false
local vspd = 0
local jumpSpeed = 10

local ground = display.newImage(“ground.png”)
ground.x = display.contentWidth / 2
ground.y = display.contentHeight - ground.contentHeight

physics.addBody(ground,“static”,{friction=0.3,bounce=0})

local player = display.newImage(“crate.png”,100,500)
player.myName = “player”

physics.addBody(player,{density=10.0,friction=0.3,bounce=0})

local function onCollision(self,event)
if (event.phase == “began”) then
ground = true
vspd = 0
elseif (event.phase == “ended”) then
ground = false
end
end

local function onTap(event)
if (ground == true) then
vspd = jumpSpeed
end
end

local function onEnter(event)
player.y = player.y - vspd
end

player.collision = onCollision
player:addEventListener(“collision”,player)
player:addEventListener(“tap”,onTap)
Runtime:addEventListener(“enterFrame”,onEnter)
[/lua]

If you see a way to fix the gliding, or just make my code better, a comment would be greatly appreciated.

Thanks,
Nick [import]uid: 229525 topic_id: 36208 reply_id: 336208[/import]

I was working on a sonic platformer demo a while ago, I used these values which worked quite well:

[lua]
physics.setGravity(0,50)

physics.addBody( sonic, “dynamic”, { density=4, friction=0, bounce=0.1, shape = sonicShape } )

[/lua] [import]uid: 93133 topic_id: 36208 reply_id: 143810[/import]

Awesome, that works perfectly. Thanks! Although, I do have a question:
In the examples, the ground usually has “static” inside of the addBody function, but you have “dynamic.” Does this really affect the jumping, or is it used for something different? Thanks, again.

Nick [import]uid: 229525 topic_id: 36208 reply_id: 143820[/import]

Hi @Gantar180,
Static bodies will never move under any force like gravity, which makes them good for ground, walls, platforms, etc. Just remember that you need at least one body set as dynamic to trigger a collision response. Static won’t collide with kinematic, but either of those will collide with dynamic, and of course dynamic with another dynamic.

Regards,
Brent Sorrentino [import]uid: 200026 topic_id: 36208 reply_id: 143869[/import]

Okay, that makes sense. Thanks for the responses, guys, they were a big help.

-Nick [import]uid: 229525 topic_id: 36208 reply_id: 143902[/import]

I was working on a sonic platformer demo a while ago, I used these values which worked quite well:

[lua]
physics.setGravity(0,50)

physics.addBody( sonic, “dynamic”, { density=4, friction=0, bounce=0.1, shape = sonicShape } )

[/lua] [import]uid: 93133 topic_id: 36208 reply_id: 143810[/import]

Awesome, that works perfectly. Thanks! Although, I do have a question:
In the examples, the ground usually has “static” inside of the addBody function, but you have “dynamic.” Does this really affect the jumping, or is it used for something different? Thanks, again.

Nick [import]uid: 229525 topic_id: 36208 reply_id: 143820[/import]

Hi @Gantar180,
Static bodies will never move under any force like gravity, which makes them good for ground, walls, platforms, etc. Just remember that you need at least one body set as dynamic to trigger a collision response. Static won’t collide with kinematic, but either of those will collide with dynamic, and of course dynamic with another dynamic.

Regards,
Brent Sorrentino [import]uid: 200026 topic_id: 36208 reply_id: 143869[/import]

Okay, that makes sense. Thanks for the responses, guys, they were a big help.

-Nick [import]uid: 229525 topic_id: 36208 reply_id: 143902[/import]

I was working on a sonic platformer demo a while ago, I used these values which worked quite well:

[lua]
physics.setGravity(0,50)

physics.addBody( sonic, “dynamic”, { density=4, friction=0, bounce=0.1, shape = sonicShape } )

[/lua] [import]uid: 93133 topic_id: 36208 reply_id: 143810[/import]

Awesome, that works perfectly. Thanks! Although, I do have a question:
In the examples, the ground usually has “static” inside of the addBody function, but you have “dynamic.” Does this really affect the jumping, or is it used for something different? Thanks, again.

Nick [import]uid: 229525 topic_id: 36208 reply_id: 143820[/import]

Hi @Gantar180,
Static bodies will never move under any force like gravity, which makes them good for ground, walls, platforms, etc. Just remember that you need at least one body set as dynamic to trigger a collision response. Static won’t collide with kinematic, but either of those will collide with dynamic, and of course dynamic with another dynamic.

Regards,
Brent Sorrentino [import]uid: 200026 topic_id: 36208 reply_id: 143869[/import]

Okay, that makes sense. Thanks for the responses, guys, they were a big help.

-Nick [import]uid: 229525 topic_id: 36208 reply_id: 143902[/import]

I was working on a sonic platformer demo a while ago, I used these values which worked quite well:

[lua]
physics.setGravity(0,50)

physics.addBody( sonic, “dynamic”, { density=4, friction=0, bounce=0.1, shape = sonicShape } )

[/lua] [import]uid: 93133 topic_id: 36208 reply_id: 143810[/import]

Awesome, that works perfectly. Thanks! Although, I do have a question:
In the examples, the ground usually has “static” inside of the addBody function, but you have “dynamic.” Does this really affect the jumping, or is it used for something different? Thanks, again.

Nick [import]uid: 229525 topic_id: 36208 reply_id: 143820[/import]

Hi @Gantar180,
Static bodies will never move under any force like gravity, which makes them good for ground, walls, platforms, etc. Just remember that you need at least one body set as dynamic to trigger a collision response. Static won’t collide with kinematic, but either of those will collide with dynamic, and of course dynamic with another dynamic.

Regards,
Brent Sorrentino [import]uid: 200026 topic_id: 36208 reply_id: 143869[/import]

Okay, that makes sense. Thanks for the responses, guys, they were a big help.

-Nick [import]uid: 229525 topic_id: 36208 reply_id: 143902[/import]