dpawlows
dpawlows

Reputation: 403

PHYSICSJS: body shrinks when static

I have a very simple animation- just a rectangle sitting on a polygon. When I make the polygon static, it shrinks. Ultimately, I just want to do an inclined plane model. Very simple. What am I missing?:

define(
    [
    'underscore',
    'jquery',
    'physicsjs'

    ], 
    function(underscore,$,
        Physics
   ) {

Physics(function(world){
      var viewWidth = 700;
      var viewHeight = 500;
      var center = Physics.vector(viewWidth, viewHeight).mult(0.5)
      var renderer = Physics.renderer('canvas', {
        el: 'viewport',
        width: viewWidth,
        height: viewHeight,

    });

  // add the renderer
  world.add( renderer );

var  ang = 38
var square = Physics.body('rectangle',{
  x: 320,
  y: 380,
  width: 50,
  height: 25,
  vx:0.0,

  angle:ang*Math.PI/180.,
  styles: {
    fillStyle: '#d33682'
  }

});
world.add(square);


world.add( Physics.body('convex-polygon', {
    x: 400,
    y: 500,
    vx: 0,
    cof: 1,
    vertices: [
        {x: 0, y: 0},
        {x: 400, y: 0},
        {x: 0, y: -300},

    ],
    treatment: 'static',
  styles: {
    fillStyle: '#FFEF73'
  }
}) );



world.add(Physics.behavior('constant-acceleration'))

var bounds = Physics.aabb(0,0,viewWidth,viewHeight);

world.add(Physics.behavior('edge-collision-detection', {
  aabb: bounds,
  restitution: 0.3
}));
world.add(Physics.behavior('body-impulse-response'))


world.add(Physics.behavior('body-collision-detection', {
}));
world.add(Physics.behavior('sweep-prune'));

Physics.util.ticker.on(function(time,dt){
  world.step(time);
});

Physics.util.ticker.start();

world.on('step',function(){
  world.render();
});

});
});

Upvotes: 0

Views: 239

Answers (1)

Jasper
Jasper

Reputation: 1193

There are a combination of things that make it look like the shape is "shrinking".

What's actually happening is that your viewport size is smaller than the triangle. When you set it to static, it won't be constrained within the edges so part of it is outside the rendering area. When you set it to "dynamic" it will jump up into the rendering area as dictated by the "edge-collision-detection".

So solve this, try shrinking the triangle, or increasing the size of your viewport.

Upvotes: 2

Related Questions