Colliders do not collide properly
See original GitHub issueDescribe the bug Some of my objects do not collide as they should, sometimes even collide outside each other’s shape. It slightly seems like the colliders of objects are somehow shifted from their position.
Expected behavior I set up colliders for space trash and laser beam in the space shooter game. But they are not computed properly. Objects are slowly rotating and are randomly resized at the beginning of the game. Each piece of space trash had the rectangle shape and the laser have the same shape as well. The laser beam should end at the moment it hit the space trash. But the beam sometimes goes through the objects. And my rocket sometimes collides with the trash even if it is outside its shape (rocket has polygon shape).
Screenshots (recommended)
The glitch:
The colliders:
The code: Space trash object (OnCreate):
this.undestroyable = true;
this.rotation = (ct.random(360));
this.scale.x = (ct.random(3) + 0.5);
this.scale.y = this.scale.x;
this.rotationSpeed = ct.random(0.5);
this.x += (ct.random(500) - 250);
this.y += (ct.random(500) - 250);
Space trash object (OnStep):
this.rotation += this.rotationSpeed * ct.delta; //trash is not moving
Function called on player:
function createLaser(player, dir) {
var direction = (player.direction + dir) % 360;
if (ct.room.timer < 300) return;
i = 0;
while (true) {
i++;
var laser = (ct.types.copy("Laser", player.x + ct.u.ldx(25 * i, direction), player.y + ct.u.ldy(25 * i, direction)));
if (laser.x < 0 || laser.x > ct.roomWidth || laser.y < 0 || laser.y > ct.roomHeight) {
return;
}
laser.rotation = (direction + 90) % 360;
for (var collider of ct.place.occupied(laser, laser.x, laser.y, 'Hitable', true)) {
if (collider != player) { //ship cannot shoot itself
laser.show(); //collision effect
if (!collider.undestroyable) collider.kill = true;
if (collider.hp)
collider.hp -= ct.delta;
return;
}
}
}
}
Versions:
- OS: Windows 10
- ct.js version: 1.0.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
The fix will be shipped in the nearest release