Moveable box - Objects falling through
Forum » General / Help » Moveable box - Objects falling through
Started by: Mojo (guest)
On: 1257342843|%e %b %Y, %H:%M %Z|agohover
Number of posts: 12
rss icon RSS: New posts
Moveable box - Objects falling through
Mojo (guest) 1257342843|%e %b %Y, %H:%M %Z|agohover

I'm currently trying to make a box act as the floor for a game, with the user being able to rotate this box in the x and z axis to move the objects that are on the box.

As it stands the box is able to rotate fine, however when the rotation direction is changed the objects sat on the top of it begin to move through the box. The box is set to immovable and the physics body is rotated as the box is rotated so i don't know what it could be.

Any ideas?

Thanks

unfold Moveable box - Objects falling through by Mojo (guest), 1257342843|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
PGlynnPGlynn 1257354638|%e %b %Y, %H:%M %Z|agohover

yea unfortunatly boxes are iffy with collisions. More so with smaller scaled or thin boxes. Take a look at this post here : http://jiglibx.wikidot.com/forum/t-188737/lower-scaled-primitives-cause-jittery-physics-against-other-primitives.

It sounds like since you move the immovable you wake up everything ontop of it or touching.

If possible, try using a plane instead. you'll notice much more solid collisions.

also you probably shouldnt use a body with a plane. You can use the collision skin alone and then use newposition and neworientation in the collision skin to transform it. Take a look at planeobject.cs in jigglegame to see how to create a collision skin without body. ( note : theres a body constructed there in the .cs but its not actually used for physics. )

last edited on 1257354759|%e %b %Y, %H:%M %Z|agohover by PGlynn + show more
unfold Re: Moveable box - Objects falling through by PGlynnPGlynn, 1257354638|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
Mojo (guest) 1257362774|%e %b %Y, %H:%M %Z|agohover

I'm now trying to use a modified plane to carry it out as suggested, using the planeobject.cs with rotation code added in using

Matrix rotation = this.PhysicsBody.Orientation;
Vector3 position = this.PhysicsBody.Position;

rotation *= Matrix.CreateRotationX(0.0001f);
this.PhysicsBody.MoveTo(position, rotation);

to move it in the X axis.

I need to set the body to immovable as otherwise the sphere falls through it, however when the ball is sat ontop of the plane any changes to the planes angle are not affected in the sphere. This means the ball just stays on the first point and won't move when the plane rotates. I assume this is to do with collision skins not updating on the plane?

unfold Re: Moveable box - Objects falling through by Mojo (guest), 1257362774|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
Nic (guest) 1257364950|%e %b %Y, %H:%M %Z|agohover

I'm more experience with Havok than JiglibX, in Havok objects resting on a mesh would not be affected by that meshes movement unless velocity was applied. Simply changing the position would not work. Are you rotating the plane by setting its orientation, or be applying an angular velocity?

unfold Re: Moveable box - Objects falling through by Nic (guest), 1257364950|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
PGlynnPGlynn 1257365093|%e %b %Y, %H:%M %Z|agohover

actually the PhysicsBody is not tied to the collision at all.

instead of using MoveTo on the PhysicsBody use this

Matrix rotation = PhysicsSkin.NewTransform.Orientation;
Vector3 position = PhysicsSkin.NewTransform.Position;

rotation *= Matrix.CreateRotationX(0.0001f);

this.PhysicsSkin.NewTransform = new Transform(position, rotation);

or if your just wanting to rotate the skin like in the function above

this.PhysicsSkin.ApplyLocalTransform(new Transform(Vector3.Zero, Matrix.CreateRotationX(0.0001f)));
last edited on 1257365262|%e %b %Y, %H:%M %Z|agohover by PGlynn + show more
unfold Re: Moveable box - Objects falling through by PGlynnPGlynn, 1257365093|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
Mojo (guest) 1257367410|%e %b %Y, %H:%M %Z|agohover

Even when using the new code you suggested the sphere is still falling through the plane when the rotation direction is changed quickly, for example when its rolling to one way on the plane, when the plane is then rotated the ball will begin to fall into the plane and then fall out the bottom of it if it has dropped too far.

unfold Re: Moveable box - Objects falling through by Mojo (guest), 1257367410|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
Mojo (guest) 1257368035|%e %b %Y, %H:%M %Z|agohover

I also tried to use

this.PhysicsSkin.NewTransform = new Transform(position, rotation);

however it claims it is read only

unfold Re: Moveable box - Objects falling through by Mojo (guest), 1257368035|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
Mojo (guest) 1257444735|%e %b %Y, %H:%M %Z|agohover
public Floor(Game game, Model model, float d)
            : base(game, model)
        {
            body = new Body();

            collision = new CollisionSkin(null);
            collision.AddPrimitive(new JigLibX.Geometry.Plane(Vector3.Up, d), new MaterialProperties(0.2f, 0.7f, 0.6f));
            PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision);

            body.ApplyGravity = false;

        }

        public override void ApplyEffects(BasicEffect effect)
        {
            effect.DiffuseColor = new Vector3(200.0f,0.0f,0.0f);
        }

        public void rotate(int direction)
        {

            if (direction == 1)
            {
                Matrix rotation = this.PhysicsBody.Orientation;
                Vector3 position = this.PhysicsBody.Position;

                rotation *= Matrix.CreateRotationX(0.0001f);
                this.PhysicsBody.MoveTo(position, rotation);

                this.PhysicsSkin.ApplyLocalTransform(new Transform(Vector3.Zero, Matrix.CreateRotationX(0.0001f)));

            }          
        }
}

This is the code i'm using to create the floor as a plane (there are another 3 movement directions i've left out as they are the same as the 1st), however it's now experiencing a problem whereby the sphere will land on the plane and when the planes rotation is changed the ball will drop down onto this lower place but not roll. Is this due a force needing to be applied in order to make the sphere roll?

Also when the plane is rotated the other way the sphere will not move up the plane, it simply falls through it. E.G. if the ball is on the left edge which is lower down than the right, plane is then rotated to life the left side up however the sphere does not follow this movement and instead remains stationary.

Any ideas?

unfold Re: Moveable box - Objects falling through by Mojo (guest), 1257444735|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
PGlynnPGlynn 1257455354|%e %b %Y, %H:%M %Z|agohover

try taking the in game rotation adjustment out and creating the plane on with (instead of Vector3.Up) Vector3.Transform(Vector3.Up, Matrix.CreateRotationX(0.0001f))

see if rolling occurs without applying local transform. It might be that the plane primitive just doesnt like transforms.

also you might want to try going back to a box on a immoveable body if thats the case. just make sure your box is thick.

unfold Re: Moveable box - Objects falling through by PGlynnPGlynn, 1257455354|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
Mojo (guest) 1257458346|%e %b %Y, %H:%M %Z|agohover

I've tried out the suggestions you made and the sphere still fails to roll on the plane.

The box, no matter how thick, doesn't like changing rotation direction and so the sphere falls through it still when its rotation is changed to opposite way in which the sphere is moving.

unfold Re: Moveable box - Objects falling through by Mojo (guest), 1257458346|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
PGlynnPGlynn 1257468044|%e %b %Y, %H:%M %Z|agohover

are you using the SphereObject.cs from jigglegame?

the thing that throws me off is that your getting no rotation on the ball.

are you working in a empty scene? like just the box and the sphere? its possible that your not removing some collisions out from the example project and the ball is colliding with those. i'm really not sure why this would happen other than that or some messed up values in the physics system.

if you don't have any rotation make sure that your inertia matrix values for the sphere's body are non zero. They shouldnt be if you're calling SetMass inside the sphereobject.cs

last edited on 1257468063|%e %b %Y, %H:%M %Z|agohover by PGlynn + show more
unfold Re: Moveable box - Objects falling through by PGlynnPGlynn, 1257468044|%e %b %Y, %H:%M %Z|agohover
Re: Moveable box - Objects falling through
ArdmarkArdmark 1257522558|%e %b %Y, %H:%M %Z|agohover

E.G. if the ball is on the left edge which is lower down than the right, plane is then rotated to life the left side up however the sphere does not follow this movement and instead remains stationary.

I had a similar problem with a ball rolling on a mesh, when I rotated the mesh the ball did not roll down.
Instead of CollisionSkin.ApplyLocalTransform(Transform transform), I used this instead:

        public void ApplyLocalTransformAbsolute(Transform transform)
        {
            for (int prim = primitivesNewWorld.Count; prim-- != 0; )
            {
                //t = primitivesLocal[prim].Transform;
                primitivesLocal[prim].Transform = transform;
            }

            SetTransform(ref transformOld, ref transformNew);
        }

Don't know if it will fix a similar problem with boxes though.
unfold Re: Moveable box - Objects falling through by ArdmarkArdmark, 1257522558|%e %b %Y, %H:%M %Z|agohover
New post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License