Howdy!
Im trying to create a body (with 2 shapes) to simulate a balance (not sure if i called it right)!
so first shape is a rectangle like 200x12.5 with density>0
second shape is a circle with its radius 12.5 and density=0.
The body is made of these 2 shapes.
But the problem is its nto static, the body should have been pined because the second shape has density 0 right? and the rectangle should have moved like in a circle because its not static like a balance! Instead it falls down like the circle has density aswell.
Why this doesnt happen?
If im not doing something wrong what would be the method to achieve what i want?
Heres the code:
Thanks 😀.
Im trying to create a body (with 2 shapes) to simulate a balance (not sure if i called it right)!
so first shape is a rectangle like 200x12.5 with density>0
second shape is a circle with its radius 12.5 and density=0.
The body is made of these 2 shapes.
But the problem is its nto static, the body should have been pined because the second shape has density 0 right? and the rectangle should have moved like in a circle because its not static like a balance! Instead it falls down like the circle has density aswell.
Why this doesnt happen?
If im not doing something wrong what would be the method to achieve what i want?
Heres the code:
Code: Select all
package
{
import Box2D.Dynamics.b2World;
import flash.display.MovieClip;
import Box2D.Common.Math.b2Vec2;
import Box2D.Collision.b2AABB;
import Box2D.Collision.Shapes.b2PolygonDef;
import Box2D.Collision.Shapes.b2CircleDef;
import flash.display.Sprite;
import Box2D.Dynamics.b2Body;
import Box2D.Dynamics.b2BodyDef;
import flash.events.Event;
import Box2D.Collision.b2ContactPoint;
import Box2D.Collision.b2Manifold;
import Box2D.Dynamics.Contacts.b2Contact;
import Box2D.Collision.b2Collision;
import Box2D.Collision.b2ContactPoint;
import Box2D.Dynamics.b2ContactListener;
import flash.events.MouseEvent;
import flash.events.EventDispatcher;
import flash.display.DisplayObject;
import flash.geom.Point;
import flash.display.DisplayObjectContainer;
public class WoodRectangle5BalanceActor extends Actor
{
public var woodRectangle5BalanceBody:b2Body;
public function WoodRectangle5BalanceActor(parent:DisplayObjectContainer, location:Point, initVel:Point)
{
var woodRectangle5BalanceSprite=new WoodRectangle5Balance();
parent.addChild(woodRectangle5BalanceSprite);
var woodRectangle5BalanceShapeDef:b2PolygonDef=new b2PolygonDef();
woodRectangle5BalanceShapeDef.vertexCount=4;
b2Vec2(woodRectangle5BalanceShapeDef.vertices[0]).Set(200/Vals.RATIO, -12.5/Vals.RATIO);
b2Vec2(woodRectangle5BalanceShapeDef.vertices[1]).Set(200/Vals.RATIO, 12.5/Vals.RATIO);
b2Vec2(woodRectangle5BalanceShapeDef.vertices[2]).Set(-200/Vals.RATIO, 12.5/Vals.RATIO);
b2Vec2(woodRectangle5BalanceShapeDef.vertices[3]).Set(-200/Vals.RATIO, -12.5/Vals.RATIO);
woodRectangle5BalanceShapeDef.density=5;
woodRectangle5BalanceShapeDef.friction=0.65;
woodRectangle5BalanceShapeDef.restitution=0;
var woodRectangle5BalanceShapeDef2:b2CircleDef=new b2CircleDef();
woodRectangle5BalanceShapeDef2.radius=12.5/Vals.RATIO;
woodRectangle5BalanceShapeDef2.density=0;
woodRectangle5BalanceShapeDef2.friction=0.65;
woodRectangle5BalanceShapeDef2.restitution=0;
var woodRectangle5BalanceBodyDef:b2BodyDef=new b2BodyDef();
woodRectangle5BalanceBodyDef.position.Set(location.x/Vals.RATIO, location.y/Vals.RATIO);
woodRectangle5BalanceBody=Vals.world.CreateBody(woodRectangle5BalanceBodyDef);
woodRectangle5BalanceBody.CreateShape(woodRectangle5BalanceShapeDef);
woodRectangle5BalanceBody.CreateShape(woodRectangle5BalanceShapeDef2);
woodRectangle5BalanceBody.SetMassFromShapes();
woodRectangle5BalanceBody.m_angularDamping=0.05;
var velocityVector:b2Vec2=new b2Vec2(initVel.x/Vals.RATIO, initVel.y/Vals.RATIO);
woodRectangle5BalanceBody.SetLinearVelocity(velocityVector);
super(woodRectangle5BalanceBody, woodRectangle5BalanceSprite);
}
}
}
Thanks 😀.