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]