I have been designing a simple space shooter, which involves a ship at the bottom of the screen firing lasers at enemies coming down from above.
With the latest public build 2381 the collisions between the laser and the enemy are only being detected about 1/3 of the time, based on my onCollision event. It was working fine with the earlier public build however.
I’m just wondering if what I am doing is correct, as it was working before… or maybe I was just lucky.
Here is the code for the laser my ship fires:
physics.addBody(laser, "dynamic") laser.gravityScale = 0 laser.isSensor = true -- prevents laser from becoming crooked when coming out of my ship
And for the enemy:
physics.addBody(enemy, "dynamic") enemy.gravityScale = 0 -- don't move with gravity enemy.isSensor = true -- don't bounce on impact with my ship
These physics bodies are all newImageRects. I’ve added a ‘collision’ event listener to the laser and ship, but not to the enemy.
I’ve just noticed that if the laser is fired slower (I am using transition.to), then its collisions with the enemy are actually detected. But this is far too slow. Is there a workaround in this build? I tried making the laser a little bit wider and a little bit longer but that didn’t help.
Can you tell me the size of the physics bodies in question? As in, width and height? By your code, I see you’re using the auto-trace body method (which is fine), so I need to know the size of the images on which these bodies are being created.
I was using transition.to to move the laser. If I made the transition time shorter, there would be big gaps between each laser movement on the screen, kind of like a ball bouncing across a floor rather than rolling on it. So, there is a chance the laser would skip over the enemy ship rather than hitting it.
To fix this issue I made the laser much longer, so that there are barely any gaps in movement. This seems to work so far. The earlier public build however was not this picky.
I’ve just noticed that if the laser is fired slower (I am using transition.to), then its collisions with the enemy are actually detected. But this is far too slow. Is there a workaround in this build? I tried making the laser a little bit wider and a little bit longer but that didn’t help.
Can you tell me the size of the physics bodies in question? As in, width and height? By your code, I see you’re using the auto-trace body method (which is fine), so I need to know the size of the images on which these bodies are being created.
I was using transition.to to move the laser. If I made the transition time shorter, there would be big gaps between each laser movement on the screen, kind of like a ball bouncing across a floor rather than rolling on it. So, there is a chance the laser would skip over the enemy ship rather than hitting it.
To fix this issue I made the laser much longer, so that there are barely any gaps in movement. This seems to work so far. The earlier public build however was not this picky.