Hello, we are having some trouble with setting up character bounce equally off the platform. Just setting character bounce does make him bounce but it doesn`t bounce at equal height.
Here is the code from physics, platform and character setup
[ local physics = require(“physics”)
–physics.setScale(40)
physics.start()
physics.setGravity(0, 50)
physics.setPositionIterations( 20 )
physics.setVelocityIterations( 8 )
local function heroJump(event)
if ( hero.inJump == false and event.phase == “began” ) then
hero.inJump = true
vx = (event.x - hero.x) / 13
hero:applyLinearImpulse( vx, -115, hero.x, hero.y )
elseif (event.phase == “ended”) then
end
end
local function makePlatform()
local platform = display.newImageRect(“woodplatform.png”, 300, 32)
platform.isSensor = true
platform.collType = “passthru”
--platform.isVisible=true
physics.addBody( platform, “static”, { density=1.0, bounce=0.2, friction=1} )
return platform
end
hero = display.newImageRect(“egg5.png”, 80 , 100)
hero.x = centerX
hero.y = screenH - 180
physics.addBody( hero, “dynamic”, { radius=40, density=1, friction = 0.7, bounce = 0.8 })
hero.isFixedRotation = true
--hero.linearDamping = 25
hero.isSensor = false
hero.inJump = false
gameGroup:insert(hero)
function hero:collision( event )
local vx,vy = self:getLinearVelocity()
if ( event.phase == “began” ) then
local collType = event.other.collType
if ( vy >= 0 and self.inJump == true ) then self.inJump = false end
if ( collType == “enemy” ) then
self.inJump = true
print(“gfdgh”)
transition.cancel()
end
self:applyLinearImpulse( nil, vy*0.0001, self.x, self.y )
if ( self.setAsSensor == true ) then
if ( collType == “solidV” ) then self:setLinearVelocity( -vx,vy )
elseif ( collType == “solidH” ) then self:setLinearVelocity( vx,-vy*0.5 )
elseif ( collType == “enemy” ) then self:setLinearVelocity( -vx,-vy )
end
end
]
So is there something we overlooked.