A modular, extendable, and easy-to-use physics engine for JavaScript.
Questions tagged [physicsjs]
47 questions
1
vote
1 answer
How to change color of a circle in PhysicsJS?
I have a cells array of white circles. Every world.step or so, I want to change one random circle to red. I can access and change the color of the circle like this:
var n = Math.floor(Math.random()*100);
cells[n].styles.fillStyle = colors.red;
This…

shurup
- 751
- 10
- 33
1
vote
1 answer
Create a ring body in PhysicsJS
I am currently working on a project that requires a circular ring shaped body. How can I achieve this? I have tried to use a the convex-polygon body with vertices similar to those of a circle but I am getting a The vertices specified do not match…

FlamingPickle
- 199
- 1
- 3
- 14
1
vote
2 answers
Proper use of Physics.aabb.union()
I'm learning PhysicsJS, and I tried using union like so:
// Window bounds
var rect1 = Physics.aabb(0, 100, 300, 200);
var rect2 = Physics.aabb(100, 0, 200, 300);
var viewportBounds = Physics.aabb.union(rect1, rect2);
// Constrain bodies to these…

Thomas
- 5,810
- 7
- 40
- 48
1
vote
1 answer
Set scale of a body and have bitmap match scaling
I'd like to know if there's a way to get and set the scale of a physicsjs body and have the bitmap assigned to the view of the body scale with it. I see no reference to scale in the state or geometry objects, and trying to set the width or height…

Ribs
- 1,449
- 2
- 13
- 27
1
vote
2 answers
Physicsjs - Using sprite sheet to assign parts of one bitmap to multiple bodies
I'd like to create a sequence of letters that can be broken apart. Ideally I'd only load one spritesheet to generate the views of the different letters. I am assigning images to the view of bodies as follows:
// letter is a physicsjs rectangle…

Ribs
- 1,449
- 2
- 13
- 27
1
vote
1 answer
PhysicsJs - how to remove a world behavior, "constant-acceration' after it has been added
My behaviors on initialization are added as follows:
world.add([
Physics.behavior('interactive', { el: renderer.el }),
Physics.behavior('constant-acceleration'),
Physics.behavior('body-impulse-response'),
…

Ribs
- 1,449
- 2
- 13
- 27
1
vote
1 answer
PhysicsJS change circle radius
After collision of 2 dots i want they make 1 dot with double radius so my code
world.on("collisions:detected", function(data) {
data.collisions[0].bodyA.mass *=2
data.collisions[0].bodyA.radius *=2
data.collisions[0].bodyB.mass = 0
…

mutant_america
- 738
- 6
- 18
1
vote
1 answer
PhysicsJS - Collision between two bodies never ends
I've got this simple js:
Physics(function( world ){
//Defining object
var renderer = Physics.renderer('canvas', {
el: 'viewport', // id of the canvas element
width: 500,
height: 200
…

Nemus
- 1,322
- 2
- 23
- 47
1
vote
1 answer
Is it possible to create a concave polygon in PhysicsJS?
I know we are able to create a convex polygon. How about concave polygon? Is it possible to combine two convex polygons then group them to form a concave one? I know Box2D can do that.

singuyen
- 118
- 1
- 5
1
vote
1 answer
Remove a behavior for a specific body after being added into the world
Is it possible to remove a Behavior for a specific Body after already being added it to the world? For example, you have a tank which has been suffered gravity, collision behaviors..., then you kill it by colliding the rocket with the tank, then you…

singuyen
- 118
- 1
- 5
1
vote
1 answer
PhysicsJS - How to rotate an element to look at the mouse position
I'm trying to rotate a rectangle to always point at the mouse position.
I've tried this:
document.getElementById('viewport').onmousemove = function(e){
var scratch = Physics.scratchpad();
mousePos = scratch.vector().set(e.x, e.y);
…

Konz
- 13
- 2
1
vote
1 answer
Aggregate Bodies in PhysicsJS
I would like to make a custom physicsjs body type called "player" which is a composition of 2 circles and one square. The figure would look like a square with a circle attached to the left and right sides of the square. I was thinking of just making…

lufthansa747
- 1,923
- 3
- 26
- 39
1
vote
1 answer
PhysicsJS - moving an object
I'm trying to figure out how to use PhysicsJS. I first off just want to simply figure out how to change lets say a position or a speed of an object on click... but I just cant figure it out!
( function()
{
var viewWidth = 500,
viewHeight =…

Luke Snowden
- 4,056
- 2
- 37
- 70
0
votes
1 answer
How to add text to canvas with PhysicsJS
I'm doing a simple project with Physics.JS and I want to be able to add text to a PhysicsJS World. I looked in the documentation but I couldn't find something that can allow me to do such thing. Is there a way to add text and to also be able to…

Darko
- 39
- 1
- 6
0
votes
1 answer
PhysicsJS - How to find a body by its label (or other value)
How should the findOne method be properly used? (http://wellcaffeinated.net/PhysicsJS/docs/#Physics-world-prototype-findOne)
This code returns the error: Uncaught TypeError: Cannot read property 'label' of undefined
var theBall = world.findOne([{…

Steve
- 3
- 2