Sinova/Collisions

multiplayer sample

Closed this issue · 6 comments

hey, can any help me.

can someone give me a little example. tank in multiplayer, with node.js.
just don't get it...
thanks

https://stackoverflow.com/help/how-to-ask

what are you trying to do exactly? what have you done so far ?

I'am testing the other Collision
https://github.com/Prozi/detect-collisions

But, the Demo Code is not working.

const Collisions = require('detect-collisions');
// Create the collision system
const system = new Collisions();

// Create a Result object for collecting information about the collisions
const result = system.createResult();

// Create the player (represented by a Circle)
const player = system.createCircle(100, 100, 10);

// Create some walls (represented by Polygons)
const wall1 = system.createPolygon(400, 500, [[-60, -20], [60, -20], [60, 20], [-60, 20]], 1.7);
const wall2 = system.createPolygon(200, 100, [[-60, -20], [60, -20], [60, 20], [-60, 20]], 2.2);
const wall3 = system.createPolygon(400, 50, [[-60, -20], [60, -20], [60, 20], [-60, 20]], 0.7);

// Update the collision system
system.update();

// Get any potential collisions (this quickly rules out walls that have no chance of colliding with the player)
const potentials = player.potentials();

// Loop through the potential wall collisions
for(const wall of potentials) {
    // Test if the player collides with the wall
    if(player.collides(wall, result)) {
        // Push the player out of the wall
        player.x -= result.overlap * result.overlap_x;
        player.y -= result.overlap * result.overlap_y;
    }
}

Testing on Node.js.

Error:
TypeError: Collisions is not a constructor

please contact Prozi, if you are using his collisions fork... not us.

We are only concerned about https://github.com/Sinova/Collisions here

Prozi commented

@Maeggi

Fixed in 2.4.1

update and run

yarn demo

then open http://localhost:8080 or http://localhost:8080?stress=test

thanks Prozi,

please consider enabling github issues (in settings) in the fork

Prozi commented

done thanks @GrosSacASac