Hi,
I tried to increase the speed of my game using physics.setScale. Everything was feeling sluggish otherwise.
Here is a sample code. If anyone would be so kind to try and explain to me:
- Why does the ball go through the platform?
I get the following console output:
platform height: 450
ball height: 428.65112304688
which indicates that the ball is still over the platform when the event is fired. The first thing we do is to set isSensor = false.
2. Why do none of the following options
- isBullet = true – (tried on ball and/or platform)
- physics.setContinuous(enabled)
- physics.setPositionIterations(300)
- physics.setVelocityIterations(300)
seem to have any effect on the collision detection? Whatever combination of the above I use, the ball’s height is exactly the same to the billionth of pixel when the event is fired.
If any of the options could affect positively the detection of collision thanks to “real time detection” instead of “frame” detection, I believe the height would be different.
The only option that had a tiny impact was fps = 60 instead of 30, but the ball stills goes through.
Thanks
endy
[lua]local physics = require(“physics”)
physics.start()
– physics.setPositionIterations( 300 )
– physics.setVelocityIterations( 300 )
– physics.setContinuous(enabled)
physics.setGravity(0,9.8)
local jumpPlatform = display.newRect( 120, 450, 100, 20 )
local ball = display.newCircle(150,350,20)
---- case 1: low speed. Works as expected
– physics.setScale(60)
– physics.addBody( ball, “dynamic”, { friction=0.2,density = 1.2} )
---- case 2: high speed, ball goes through
physics.setScale(300)
physics.addBody( ball, “dynamic”, { friction=0,density = 9} )
physics.addBody( jumpPlatform, “static”, { friction=0,isSensor = true} )
– jumpPlatform.isBullet = true
– ball.isBullet = true
function onFloorCollision(self,event )
if event.phase == “began” then
print(“platform height:”, self.y)
print(“ball height:”, event.other.y)
self.isSensor = false
self:setFillColor( 1,0,0 )
end
end
jumpPlatform.collision = onFloorCollision
jumpPlatform:addEventListener( “collision”, jumpPlatform )
ball:applyLinearImpulse(0, -1, ball.x, ball.y)[/lua]