wrong collitions

Sep 26, 2011 at 7:29 AM



does some1 know why my red rectangle is levitating !!


 Body b=BodyFactory.CreateRectangle(g.World, size.width, size.height, 1f);
            b.BodyType = bt;
            b.Position = measures.Center;
            b.Restitution = 0f;
            b.Inertia = 0.0f;

what do i have to change ??


Sep 26, 2011 at 11:23 AM

i think its because the drawing. but why you setinertia to 0? aren't you looking for friction?

Sep 27, 2011 at 6:17 PM
Edited Sep 27, 2011 at 7:18 PM

yeah you were right,

but now i have other dobut for example i have a Ball gameComponent that takes the radious

Texture2D t = ((Game)g).Content.Load<Texture2D>("Images\\Ball");

Rectangle r = new Rectangle(TopLeftPos.X,TopLeftPos.Y,radious*2,radious*2)


Body b = BodyFactory.CreateCircle(g.World, radious, 1f);
            b.BodyType= BodyType.Dynamic;
            b.Position = r.Center;
            b.Restitution = 0.5f;
            b.Friction = 0.1f;
var v = new Rectangle(b.Position.X,b.Position.Y,r.widht,r.height);

var OriginPoint  = new Vector2(r.widht/2, r.height/2);


sp.Draw(t, v, null, c ?? Color.White, b.Rotation, OriginPoint, SpriteEffects.None, 0f);

im using this overload because i dont  want to depend on the texture's size, to draw the ball

So the thing is my balls now doesnt appear in the screen, i thing that is because the draw method use the texture width and heigt to work with the origin point, and no the rectangle

Sep 28, 2011 at 8:59 AM

why not just:

Body b = BodyFactory.CreateCircle(g.World, t.Width/2f, 1f);

Vector2 OriginPoint = new Vector2(t.Width/2f, t.Height/2f);

sp.Draw(t, b.Position, null, Color.White, b.Rotation, OriginPoint, SpriteEffects.None, 0f);