Hi !
I’m new to the forums, but I have a questions about seemingly odd results with object interactions.
The code below creates a teal colour dynamic object which has a y-axis force applied and is under no other rules except to bounce between the two white objects at top and bottom of the screen.
There other static objects that the teal object ‘slides’ by and they register a collision. The teal object seems to randomly interact with the objects (by being stopped or recoiling)
It may take a couple of runs to see the effect. I have posted a video of what happens here:
https://www.youtube.com/watch?v=8paEEUC0HTo
Does anyone know why this is happening? It would be better if the behaviour was consistent, but it seems to be random.
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local screenLeft = display.screenOriginX
local screenWidth = display.contentWidth
local screenRight = screenLeft + screenWidth
local screenTop = display.screenOriginY
local screenHeight = (display.contentHeight)
local screenBottom = screenTop + screenHeight
local WIDE = 32
local function onLocalCollision( self, event )
print(event.phase, event.other.id)
self.isFixedRotation = true
end
local physics = require( "physics" )
physics.setDrawMode( "normal") -- "hybrid" )
physics.start()
physics.setGravity(0,0);
local obj1 = display.newRect(centerX-100, screenTop+ WIDE+60, WIDE, WIDE)
obj1:setFillColor(.2, .5, .5)
physics.addBody(obj1, "dynamic", {bounce = .5, friction = 0, density=0})
obj1.collision = onLocalCollision
obj1:addEventListener( "collision")
obj1:applyForce( .2, 0, obj1.x, obj1.y )
function delayFunc(event)
obj1:applyForce( 0, 1, obj1.x, obj1.y )
local result = timer.pause( timer1 )
end
timer1 = timer.performWithDelay( 5000, delayFunc, 0 )
local function boxes(num)
local top = display.newRect(centerX-WIDE , screenTop + 32, WIDE, WIDE)
top.id ="top"
physics.addBody(top, "static", {bounce = 1, friction=0, density=0})
local bottom = display.newRect(centerX-WIDE ,screenBottom - WIDE, WIDE, WIDE)
bottom.id="bottom"
physics.addBody(bottom, "static", {bounce = 1, friction=0, density=0}) --
for x = 1, num do
local box = display.newRect(centerX,
screenTop+ (x * (WIDE+60)),
WIDE,
WIDE)
box.id = x
box:setFillColor(math.random(), math.random(),math.random())
physics.addBody(box, "static", {bounce = 0, friction=0, density=0})
end
end
boxes(4)