Giter Club home page Giter Club logo

planck.js's People

Contributors

1pakch avatar blidnight avatar bystrano avatar caseywebdev avatar dtgreene avatar feavy avatar florentmasson avatar haujason avatar hbaklan943 avatar ilya-ku avatar lukasdrgon avatar matthewvroman avatar necroneco avatar prozi avatar quantum64 avatar robloach avatar s-iaroshenko avatar shakiba avatar smurf667 avatar stephanemagnenat avatar thomasyonug avatar wemyss avatar zoadt 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  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

planck.js's Issues

[Suggestion] World.prototype.destroyAll

I'd like to reset a world by destroying all of its joints, bodies, etc. Was thinking of this feature. If it makes sense, please consider this email an official request for that.

Serialization

Thanks for the nice library!

Any advice on how to accurately serialize the state of a planck World? Simply iterating over all bodies/fixtures and copying their positions/velocities/vertices/etc. doesn't work for collisions in progress, etc. There are also a few Function objects in the object hierarchy, hindering more straightforward serialization mechanisms. (FWIW, serialization is something that libraries like matter.js do support out-of-the-box.) Thanks!

setting `world.step(1 / 60)` gives a very slow movement

Are all the demo setting world.step(1 / 60) ?

I use this in my gravity based program and I find the sprite moves very slow. I am using PIXI.js as the renderer and its ticker rate is 60 FPS I believe. If the world time step is unrelated to the frame rate how do I know what time step to use to get a smooth movement?

PrismaticJoint.prototype.getReactionForce returns NaN

PrismaticJoint.prototype.getReactionForce = function(inv_dt) {
   return inv_dt * (this.m_impulse.x * this.m_perp + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis);
};

This returns NaN, because this.m_perp and this.m_axis are vectors not numbers. Can't figure out how to fix this myself! Thanks again for all the work you've done on this engine!

Spatial partitioning

Hey @shakiba - I'm working on an MMO game for the Web, and part of the game design is to use a quad tree on the broadphase for spatial partitioning of events. Effectively a player would only process the physics and network events for near by quads.

I'm still new with working in planck.js, but do you have any suggestions on the right way to connect into the world step to support spatial partitioning in such a way to only process a subset of the world? perhaps bodies remain, but collision detection is reduced to a subset, or perhaps some other ideas for the right approach?

Use of Stage.js

Hi,

I had a chance to play with Planck.js and Stage.js, but separately.
I'm not js guru. In the last few days I decided to use the library without the testbed.
My first choice was to replace it with Stage.js.

I follow box2d manual hello world example, nothing super ambitious.
I have a bouncing ball on a flat surface/edge. Now I want to use Stage.js to render that on the screen.

It seems like all examples are testbed examples. Even though it supposed to be only a case of calling the world.step(timestep) function, I'm still struggling as I assume there will be something similar needed on the Stage.js side.

Would it be possible to post an example that uses Stage.js? Something really simple.

Thank you.
Chris

Math.isFinite does not exist

In lib/fixture.js:

Fixture.prototype.setDensity = function(density) {
_ASSERT && common.assert(Math.isFinite(density) && density >= 0.0);
this.m_density = density;
}

The function is just isFinite, not Math.isFinite.

[Question] Best practices: generating a fixture + static body for in-game text label

A question more than an issue.

If you were to create a game with this lib, how would generate a fixture for text representation, using an SVG path (of said text string as an outline) as input?

PS: this project seems to get a lot more attention from its author/maintainer than all others out there; thanks a lot for that. This is much appreciated, given how not easy physics engines are.

Revolute joint: misuse or bug?

I have a feeling this is not a bug, yet I remember this not happening in my (looooong ago) tests with Box2D.

When a dynamic body perfectly overlaps another, static one -- their world center coords are same -- and both are joined by a revolute joint (with default jointdef values), it seems that changing world gravity has no effect on the dynamic one; it stays in place, not rotating.

If however I offset one from the other such that they no longer overlap, the dynamic one now responds fluidly to gravity changes.

See this example .

Does this seem normal to you? Joint friction perhaps? If not, I can test this on another testbed and see what comes up.

Report last fix into dist/

Hello :) When you have time, could you please report your last fixes into the generated js files (into the dist/ folder) please ? thanks ^^

textures and images on Plank.js

Hi, i´ve been trying add images on planks.js, but i colud not make it. i´d like load images through Stage.js and planck-with-testbed to can see rendering images on my canvas. this repository have no examples with images loaders and textures. ¿is it possible, load images and textures on plank.js viewer?

Thanks. your api is amazing.

Radial Gravity Support?

Does it support radial gravity? Or have you got an implementation to show for it? Thanks.

Rebuilding planck.js used by testbed

I am porting the Top-down car demo and computing a projection of one vector on another one is quite a common operation there. Hence I implemented a projectOn method for the Vec2 class and the issue is that I am unable to run a testbed so that it picks up the new version of the Vec2 class.

While I am able to rebuild dist/planck.js using gulp so that it includes the new method it is still not picked up by the testbed. Naturally, I am wondering what goes wrong.

I am new to js so I apologize if the issue is trivial.

Vec2 normalize() return value

I was wondering whether normalize should return a reference to this rather than the old length so that it makes it possible to use it in function chaining. Or alternatively create a normal() that is a wrapper around normalize and just returns this.

See the example below:

const myVec = vec.clone()
    .sub(vec2)
    .normalize()
    .mul(0.5)
    // and so on

Really cool project by the way! My only complaint is the minimal documentation which makes it harder as I don't have an understanding of where everything is in the library yet.

Revolute joint "sticky" on the limits

I'm trying to build a revolute joint that stays at the lower limit if no button is pressed, and rotates to the upper limit when I press a button. The problem is that when the joint is on the limits, it "sticks" to them, and takes a while to start rotating.

I have built this example on JS Bin

In the example, the 'up' arrow makes the joint rotate. It responds immediately if it's between the limits, but when it's at the limits it has a delay before it starts moving.

I'm not sure if it's a problem with the library, or if there's a way to code this better so that the issue stops happening.

Thank you

how to predict the trajectories in advance

just like the table tennis game.

the ball has linearDamping and angularDamping ,is forced apply by one velocity, and collision with the wall ,then moves to anthor angle
how could i know the trajectories in advance before the ball is forced apply?

suggestions on hierarchical problem

Planck looks cool! I'm thinking about using it to prototype a simulation, where characters may drive large vehicles around in a large, top-down, 2D environment. I'd like to have characters that can walk around inside of a vehicle while it's being moved.

I'm wondering how I might model this problem with planck. 3 initial strategies that come to mind:

  • maybe there's a notion of parent<->child relationships, where I could express a movable physics body (character) as a child of another physics body (the vehicle.) Simply moving the vehicle would then move any objects inside it automatically?
  • maybe instead I just store the character position relative to the vehicle and "snap" the character body to the correct position after each physics step?
  • maybe I copy the velocity & angular velocity values from the vehicle and add them to everything in the vehicle?

Any feedback/ideas would be much appreciated!

Optimization Canvas on Cordova

Hi Shakiba.

I need know, if exist some library, tool or thecnique that allow me to make optimization with canvas on Cordova. I actually be making a game to android, but my canvas is working so slow. also, i´d want know if this implementation is viable, ¿create a game using plank.js and Stage.js?

Thank´s.

Term 'Hz' is incorrect.

In the documentation there are a few references to the variable hz

 // in each frame call word.step(hz) with fixed frequency
    world.step(1 / 60);

And that this variable is the 'frequency'. However, below this we have 1/60. This is not frequency (which is 60 Hz, not 1/60), this is the time step. The example ReadMe should be updated to reflect this.

Also from the source docs:

 680 /**
 681  * Take a time step. This performs collision detection, integration, and
 682  * constraint solution.
 683  * 
 684  * Broad-phase, narrow-phase, solve and solve time of impacts.
 685  * 
 686  * @param {float} ts Time step, this should not vary.
 687  * @param {float} dt Elapsed time, since last call.
 688  */
 689 World.prototype.step = function(ts, dt) {

RevoluteJoint limits not working

It seems like the upperAngle and lowerAngle values don't work: when setting them along with enableLimit the joint won't work anymore.
(Great work on the library, btw!)

Collision events and ECS-styled games

@shakiba congrats on this amazing work and project. I believe this is very needed in the community and it's exactly what I was looking for months ago. I ended up settling on p2.js, which also looks inspired by box2d, so it'll be easy for me to port my game to planck.js

p2.js was very good, but I'm glad to see someone crafting a clean and even refactored box2d port to JS - so thank you very much.

Of course there are many architectures when writing a game - in my case I used an ECS design to break everything into synchronous and discrete set of steps in time. However with listeners, it opens up to an asynchronous state which maybe or maybe not is compatible with ECS - what do you think?

also, what is the point of the events versus other state testing functions in a physics engine, and having an API that is friendly to an ECS or other game architectures?

"Basic World" test failing in master

My results are:
10 passing (58ms)
1 failing

  1. Basic World:
    Error: expected 0.0025000000000000005 to be near 0
    at Assertion.assert (node_modules/expect.js/index.js:96:13)
    at Assertion.expect.Assertion.near (test/testutil/expect.js:35:8)
    at Context. (test/BasicTest.js:43:17)

There is also a missing dependency on the Mocha test framework.

PS- This looks like great port of box2d to javascript, congrats.

WheelJoint: how to get anchor position, updated for current bodyB position?

More a question than an issue.

I have 3 fixtures:

  • A is a car chassis fixture
  • B is a wheel fixture
  • C is another wheel fixture

I have 2 wheel joints:

  • J1 has its anchor at center of B and axis tied to A.
  • J2 has its anchor at center of C and axis tied to A.

Now, I turn on the wheel joint motors. The car moves.

I want to draw each wheel joint's anchor in realtime, as the car moves. To do that, I need to obtain the current world coordinates of body B. Must I keep a ref to B and ask for its world point at each tick, or is there a way to obtain that info with the joint alone (I didn't see a getBodyB function for wheel joints)?

Length of DistanceJoint cannot be set through DistanceJointDef

Hallo,
I'm using a DistanceJoint to attract a DynamicBody to a static center Body. The original Box2D implementation allows setting the length of the DistanceJoint through DistanceJointDef. In planck-js the length is automatically calculated as the distance between the two anchors:

this.m_length = Vec2.distance(anchorB, anchorA);

Currently I'm overwriting m_length after creating the joint. It would be nice if the length could be specified in the definition.

Missing documentation

Where can I find the API documentation? Like the list of main classes and their methods.

Phaser 2 Integration

Is there any way to integrate planckjs in Phaser 2? I couldn't find anything related to this.

Phaser 2 has box2d integration, so i don't think it would be hard to integrate, but some hints/help wouldn't hurt :)

Also is planckjs deterministic?

Thanks!

Objects reacting to the programmatic movement of another one

I need the objects of my world to react as another 'special' object passes by and touches them. For technical reasons, I am setting the position of this special object programmatically (setting the theBody.c_position.c.x and theBody.c_position.c.y properties).

Suppose I position the special object obj at a certain point (x,y) around which there other objects. obj is located properly (I can see it moving) but it does not seem to affect the surrounding objects when touching them. Instead, it just overlaps them and is just drawn on top of them.

What am I missing here? I suspect the problem has to do with motion, but the only thing I have at hand is the desired location of the object I need to move programmatically.

Export Matrix types

Description

Working on an application in PIXI.js, and the functionality of Mat22 would facilitate some of the translation between the two libraries ( scaling for pixel => meter ).

Implementation

add the following code to index.js, and define the types in index.d.js

Code:

exports.Mat22 = require('./common/Mat22');

Type:

declare let Mat22: {
	new ( a: number, b: number, c: number, d: number ): Mat22;
	( a: number, b: number, c: number, d: number ): Mat22;

	new (a: { x: number; y: number }, b: { x: number; y: number }): Mat22;
	(a: { x: number; y: number }, b: { x: number; y: number }): Mat22;

	new (): Mat22;
	(): Mat22;

	mul(mx: Mat22, my: Mat22): Mat22;
	mul(mx: Mat22, v: Vec2): Vec2;
	mulT(mx: Mat22, my: Mat22): Mat22;
	mulT(mx: Mat22, v: Vec2): Vec2;
	abs(mx): Mat22;
	add(mx1, mx2): Mat22;
}

[SUGGESTION] rename `lib` to `src`

In most projects , the dir namelib means dependencies (the 3rd lib) , src means the source code of current project.

So , I hope you could rename lib to src

RevoluteJoint.prototype.getReactionForce returns NaN?

Hey,

Trying to get the reaction force and torque out of a joint to determine if I should remove the joint (creating "breakable" joints).

I'm not sure if this code in Planck is correct:

RevoluteJoint.prototype.getReactionForce = function(inv_dt) {
var P = Vec2.neo(this.m_impulse.x, this.m_impulse.y);
return inv_dt * P;
};

P is an object with x and y properties, and then the object is multiplied by a number? This returns NaN. Should it be p.mul(inv_dt) instead so the multiplication works correctly?

Thanks!

GearJoint between two PrismaticJoints not working - "Dot is not defined"

I'm finding that a gear joint between two revolute joints works fine, and a gear joint between a revolute and a prismatic work fine* but a gear joint between two prismatic joints causes this:

Uncaught ReferenceError: Dot is not defined
at GearJoint.solvePositionConstraints (planck.js:9663)
at Solver.solveIsland (planck.js:3533)
at Solver.solveWorld (planck.js:3384)
at World.step (planck.js:4639)

*Only if jointA is the revolute and jointB is the prismatic, not the other way around

Should be simple to reproduce. Thanks for making planck!

Haxe externs

Not an issue, but just to let you know that I am working on externs for Haxe (not shure of the best practice to post this) :

https://github.com/NicolasVereenoghe/git.vega.pixi4/tree/master/haxe/lib/planck%2Cjs

It's a first try, and for now the externs are hosted into my framework repository.

I'm going to deal with serious testing the coming days. I hope it will make the job ^^

If you're interested, try it or tell ... I may create another repository for the Haxe externs, for now I'm not sure :)

Install instructions point to wrong package

in README your install instructions are

#### NPM

    npm install stage-js --save

#### Bower

    bower install stage-js --save

I think you meant to have planck-jsinstead of stage-js

Typo on main page

Hi guys, Just to let you know typo on the landing page

"Providing a JavaScrip-friendly API"

Good job otherwise :)

Save/Load everything

Hi,
First thanks for this tremendous work! Awsome. I've tried Matter js, but I like physics in this one far better.

Anyway, I don't know if this is the place to ask (please point me somewere if it isn't), but is it possible to pause simulation, and save everything (bodies, forces, broadband, collision pairs,...). I would then continue simulation but in anytime I could "roll-back" everything to exact state as it was in moment of saving?

Thank you very much in advance!

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.