Hello great people,
I’ve spent 2 nights struggling with the above problem. As per the below, I have 4 draggable objects (UFOs) on the canvas that move on their own in an orthogonal direction when dragged in the relevant direction. I have been able to get the UFOs to stop when they hit the brown block and collect the stars on their way to the blocks. I’m struggling to get the UFOs to stop when they get to another UFO. I’ve used both the collider and overlap events, but the UFO objects cross each other instead of stopping just before they collide.
The below is a section of the code I have written to solve this problem, which doesn’t work as desired.
function loadLevel(self, levelIndex){
resetGame(ark);
let levels = getLevelObjects();
let level = levels[levelIndex];
ark.blocks = placeObjects(self, level.blocks, 'block', false);
ark.players = placeObjects(self, level.players, 'ufo', true);
ark.cows = placeObjects(self, level.cows, 'starGold', false);
self.physics.add.collider(ark.players, ark.blocks, detectBlockCollision, null, self);
// self.physics.add.collider(ark.players, ark.players, detectPlayerCollision, null, self);
self.physics.add.overlap(ark.players, ark.cows, detectCowCollision, null, self);
self.physics.add.collider(ark.players, ark.players, function(player1, player2){
// player1.setBounce(false);
// player2.setBounce(false);
console.log('overlap player 1: ' + player1.x + ' , ' + player1.y);
console.log('overlap dragged player 2: ' + player2.x + ' , ' + player2.y);
player2.setVelocityX(0);
player2.setVelocityY(0);
}, null, self);
self.input.setDraggable(ark.players);
levelText.setText ('Level: ' + currentLevel);
}
Any assistance with the technique to do this would be greatly appreciated.