Giter Site home page Giter Site logo

collisions's People

Contributors

kefniark avatar shimshamsam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

collisions's Issues

multiplayer sample

hey, can any help me.

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

confusing example about Line

I'm trying to use this package, but the example of how to create line is ambiguous:

If new Polygon(200, 5, [[-30, 0], [10, 20]]) is a line, why doesn't it only contains two point likes new Polygon(200, 5, [[-30, 0]]) ?
It looks likes a triangle.

Sweeping and linecasting

Hello,
I am using your collisions system for my game and, with some adaptation (converting it to module.exports - I couldn't get the import thing to work on node.js), it's working pretty well.
I have some questions however:

  1. Is the correct method for raycasting to create a 2 point polygon and checking its potentials? I haven't encountered issues, but there might be corner cases I don't know about.

  2. Sweeping items. Some items in my game will move pretty fast (ex. bullets) and I couldn't find a logic that handles this, therefore I think implementing pre-movement sweeping is necessary.
    I was wondering if it's a good approach to create a rectangle polygon with the widest points of the body being sweeped and a copy of the polygon at the target point. Then I check all the potentials for both, sorting them based on their distance from the original body. And for last, I use the x y overlap of the rectangle polygon (or the negative x y overlap if its closer to the original body than the middle of the rectangle of the body) as a point to move the original body to.

Thank you very much!

How to get the normal of the line I collide with?

Hi,

Thanks for this library, we're looking forward to using it. After reading the documentation, we have one question however. How would one go about calculating the rebound vector / direction when a collision occurs? For example, when bouncing a ball against a wall, how do I make it bounce in the right direction?

Thank you

Circle collision issue

I tried to use this library and realized some projectile were able to go through wall without triggering any collision (mostly circle collider).

The same issue is reproducible even in the samples.
For example, if we add few extra walls to Stress.mjs:

this.collisions.createPolygon(382.5, 255, [[-62.5, -5], [-62.5, 5], [62.5, 5], [62.5, -5]]);
this.collisions.createPolygon(507.5, 255, [[-62.5, -5], [-62.5, 5], [62.5, 5], [62.5, -5]]);
this.collisions.createPolygon(257.5, 255, [[-62.5, -5], [-62.5, 5], [62.5, 5], [62.5, -5]]);
this.collisions.createPolygon(132.5, 255, [[-62.5, -5], [-62.5, 5], [62.5, 5], [62.5, -5]]);

this.collisions.createPolygon(574.5, 697, [[-5, 62.5], [-5, -62.5], [5, -62.5], [5, 62.5]]);
this.collisions.createPolygon(574.5, 572, [[-5, 62.5], [-5, -62.5], [5, -62.5], [5, 62.5]]);
this.collisions.createPolygon(574.5, 447, [[-5, 62.5], [-5, -62.5], [5, -62.5], [5, 62.5]]);
this.collisions.createPolygon(574.5, 323, [[-5, 62.5], [-5, -62.5], [5, -62.5], [5, 62.5]]);

this.collisions.createPolygon(65, 697, [[-5, 62.5], [-5, -62.5], [5, -62.5], [5, 62.5]]);
this.collisions.createPolygon(65, 572, [[-5, 62.5], [-5, -62.5], [5, -62.5], [5, 62.5]]);
this.collisions.createPolygon(65, 447, [[-5, 62.5], [-5, -62.5], [5, -62.5], [5, 62.5]]);
this.collisions.createPolygon(65, 323, [[-5, 62.5], [-5, -62.5], [5, -62.5], [5, 62.5]]);

this.collisions.createPolygon(382.5, 764.5, [[-62.5, -5], [-62.5, 5], [62.5, 5], [62.5, -5]]);
this.collisions.createPolygon(507.5, 764.5, [[-62.5, -5], [-62.5, 5], [62.5, 5], [62.5, -5]]);
this.collisions.createPolygon(257.5, 764.5, [[-62.5, -5], [-62.5, 5], [62.5, 5], [62.5, -5]]);
this.collisions.createPolygon(132.5, 764.5, [[-62.5, -5], [-62.5, 5], [62.5, 5], [62.5, -5]]);

we can already see circle collider being able to go through some of the walls

image

Could you release 2.0.14 to npm?

Hi!

It seems like the code in master is updated and it works well when importing the module from a parcel+typescript project.

The latest npm version (2.0.13) doesn't seem to work well on that kind of project though.

Could you release a new patch version with the latest master code?

For now (in case anyone else wants to use it), I've been adding "collisions": "git://github.com/Sinova/Collisions.git#f59299c1a333542187db37e99dcf8fa65bfa7ab3" to the package.json and pointing to the latest commit. Which works, but it is not the best.

Very cool library!

Can't import with browserify and babel

Im trying desperately to import this package but can't seem to get it to work.

Installing from npm and requiring the package as I would any other package throws this error:
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

I then dug around for a few hours with babel, browserify, grunt-browserify, and did a lot of research. It just seems as though using .mjs files isn't that supported yet?

I then tried switching over to rollup however rollup had problems with most other libraries (fixing one, broke another). So i gave up on that. Babel it is.

I then tried setting this package as a git submodule, and then importing it relative to my code.
Brilliant!
But babel still didn't like the .mjs files.
So I created aliases for them all so hopefully names wouldnt mattter. I still couldn't get them to work.

Next i tried adding a grunt task to copy all the files to .js. The problem being that you're referencing the relative files with extensions. So that solution along with the aliases still don't work.

Is there any way i can get this to work without having to fork the repo? I think it would need to support standard commonjs imports.

Encapsulating body within a higher level object

I'm playing with the Tank demo and I would like to encapsulate a collision body within different objects, such as: target and bullet. This way when the bullet collides with a target, I can check what hit target (if the bullet, the tank or other) and react accordingly.

Unfortunately I can't seem to find the correct approach. When I iterate the body.potentials(); I can't backtrack to which object contained it and I can't seem to find a unique id that is assigned to a given body that I could use as reference.

Can you please advise on the correct approach?

Collisions sometimes not detecting

I have a small game with a circle player and some polygons and circles around (~1.1k colliders). Once and a while I will find that a collision is not detected between the player and an object. I don't know why this is happening as I use a class to create the objects and other objects collisions work perfectly. I don't think it's because I passed some mystical object limitation number, because objects created after the broken ones work fine.

I am using counter clock-wise polygons. Created like this:

var poly=new Polygon(x, y, ...);

system.insert(poly);

I know this repo is pretty dead but maybe someone faced a similar issue and can help. Thanks.

mjs couse trouble in create-react-app

It throws Unhandled Rejection (TypeError): __WEBPACK_IMPORTED_MODULE_1_collisions___default.a is not a constructor

If I import Collisions, { Circle, Polygon } from 'collisions';

And console.log(Collisions) gives /static/media/Collisions.c776ea0e.mjs

BVH insert issue

I was getting weird crash with the BVH tree used in this project.

After some research, I realized the issue was caused by my pooling system (which use insert/remove quite intensively). Because one of the object was created through:

const poly = system.createPolygon(200, 5, [[-30, 0], [10, 20]]);
// and not 
const poly = new Polygon(200, 5, [[-30, 0], [10, 20]]);

This API underneath do an .insert() automatically, and my code was doing a second one later.
Double .insert() can completely break the tree and create infinite loop (most of the time in potentials()).

This could be nice to avoid this kind of crash by:

  • preventing this kind of behavior
  • or automatically call remove when a double insert is detected
  • or throw an error.

In my case, even if it's a bit hacky, I just added a check on the _bhv property to prevent it:

	/**
	 * Inserts bodies into the collision system
	 * @param {...Circle|...Polygon|...Point} bodies
	 */
	insert(...bodies) {
		for(const body of bodies) {
			if (body._bvh) {
				continue;
			}
			this._bvh.insert(body, false);
		}

		return this;
	}

	/**
	 * Removes bodies from the collision system
	 * @param {...Circle|...Polygon|...Point} bodies
	 */
	remove(...bodies) {
		for(const body of bodies) {
			if (!body._bvh) {
				continue;
			}
			this._bvh.remove(body, false);
		}

		return this;
	}

Apparently there is already an error to prevent a body to be in two different tree:

throw new Error('Body belongs to another collision system');

Is it possible to report contact point(s)?

Hi,
Only overlap information reported when collision happened. Is it possible to also provide contact points in report?
Overlap information provides contact normal vector, and penetration depth. But not contact points. To implement a proper physics engine, points are also needed to apply force from that points.

Btw love the work here.

Raycasting?

Any way to achieve raycasting with your lib? Also, great work!

Declaration file

I'm using this library with typescript, and to have types and Autocomplete, I wrote a declaration file (mostly based on your nice jsdoc).

I just would like to know your preference:

  • Can I add this declaration file to this repository and add a new field in package.json :
   "types": "collisions.d.ts",

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.