Character Jumping

physics = require “physics”
physics.start()
physics.setGravity( 0, 8)

local boxGround = display.newRect(0, 450, 340, 50)
boxGround:setFillColor(140,140,140)
physics.addBody(boxGround, “static”, {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})

local boxCharacter = display.newRect( 320/2, 400, 50, 50 )
physics.addBody(boxCharacter, “dynamic”, {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})

local function boxJump (event)
if event.phase == “began” then
transition.to(boxCharacter, {time = 700, y = boxCharacter.y - 250 } )
end
end
Runtime:addEventListener(“touch”, boxJump)


I am using this code to make a box jump on the screen, but the jump is ugly like it is hitting a invisible wall. Can anyone help? Thanks

[import]uid: 39533 topic_id: 27055 reply_id: 327055[/import]

don’t use transition.to for the jump.
use the physics engine and try something like
body:applyLinearImpulse( )
http://developer.anscamobile.com/reference/index/bodyapplylinearimpulse

-finefin
[import]uid: 70635 topic_id: 27055 reply_id: 109848[/import]

Jon Beebe has a good example here

https://github.com/jonbeebe/Character-Jump [import]uid: 75779 topic_id: 27055 reply_id: 109896[/import]

Try this code…
All credits too “Brent Sorrentino” as he helped me out while i was stuck in my code… m just sharing his code to help you out…
Hope this helps you too.

Note : Change y value which is (-0.65) as per your requirements…

[code]
local function boxJump (event)
if event.phase == “began” then
local function doJump()
boxCharacter:applyLinearImpulse(0,-0.65,boxCharacter.x,boxCharacter.y)
end

boxCharacter:setLinearVelocity( 0,0 ) --set linear velocities to 0
timer.performWithDelay( 10, doJump ) --call jump impulse function after a tiny delay
end
end [import]uid: 83799 topic_id: 27055 reply_id: 109985[/import]