Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have a rectangle shape #8

Open
noobiept opened this issue Nov 19, 2012 · 2 comments
Open

Have a rectangle shape #8

noobiept opened this issue Nov 19, 2012 · 2 comments

Comments

@noobiept
Copy link

Hello, I'm trying to have a platform with a rectangle shape, and I'm not seeing how I can add that shape.

I can have the drawn part and a Particle interacting well, but the Particle has the shape of a circle. Is there a way to have a rectangle shape?

@soulwire
Copy link
Owner

CoffeePhysics isn't a rigid body engine, so it doesn't currently handle polygon collisions in that way.

One option you have is to make your square from 4 particles, connected by very stiff springs. Connect them around the perimeter of the square and in a cross. Something like:

var squareSise = 50;

// Corners
var tl = new Particle();
var tr = new Particle();
var br = new Particle();
var bl = new Particle();

// Perimeter
var s1 = new Spring(tl, tr, 50, 1.0);
var s2 = new Spring(tr, br, 50, 1.0);
var s3 = new Spring(br, bl, 50, 1.0);
var s4 = new Spring(bl, tl, 50, 1.0);

// Cross
var s5 = new Spring(tl, br, 50, 1.0);
var s6 = new Spring(bl, tr, 50, 1.0);

This will bounce off walls, thought there might be some slight elasticity as the springs compress. Also, collisions between squares won't be handled if 2 rotated squares intersect.

If you need this kind of behaviour, I suggest you use a rigid body engine like Box2d :)

@noobiept
Copy link
Author

Hey, thanks for the help.

I tried doing that but the collision detection isn't working. I'm trying to have the ball stop at the platform. If you could give this a look, I'd really appreciate it.

https://gist.github.com/4121971

(I'm using createjs, don't know if you're familiar, but I can explain if you don't understand)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants