I've got a function that spawns scooters that zip across the screen at random heights and intervals. With my code as is, they bunch-up and bound off each other when their shapes overlap, and I want to take this effect away. I never wanted to use physics in my game at all, but was forced to, in order to create custom sized hit-boxes for my scooters (sprites) that were way smaller than the bounding boxes of the scooters. Here's the code for my function:
1 2 3 4 5 6 7 8 9 10 11 | local function scooterSpawn (event) timer.performWithDelay(math.random(20,35),squareSpawn) local scooter = spriteFactory:newSpriteGroup('Scooter 1 moving right') scooter:addPhysics(physics,'dynamic',{}) scooter.x = -100 scooter.y = math.random(120,924) physics.addBody(scooter,"dynamic",{isSensor = true}) transition.to(scooter, {time = math.random(1400,1500), delay = 0, x = scooter.x + 968, onComplete=function() scooter :removeSelf() end}) end timer.performWithDelay(0,scooterSpawn,1) |
Hey Steven.
If I understand you correctly, you want to use physics to detect collisions, but not actually have the objects interact?
I would suggest adding the following to your code, between lines 7 and 8:
1 | scooter.isSensor = true |
@spider_newgent Did it ever!
I can't believe such a simple addition fixed things, I thought I'd have to completely overhaul my approach. Thank you so much!
Steven