Vehcile + CompoundBody

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Phippu
Posts: 24
Joined: Fri Jun 03, 2011 3:39 pm

Vehcile + CompoundBody

Post by Phippu »

Hi, It's me again :P

This time I have a little problem with the vehicle class. I think I know the solution but I couldn't find a way to implement it. What I have for example is the following:
- all wheels have radius 1
- the body has width and length of 1 unit and a height of 0.5

I create the vehilce using the following code. With the values from above this works quiet well (see image).

Code: Select all

            var bodies = new List<CompoundShapeEntry>
            {
                new CompoundShapeEntry(new BoxShape(2, 0.5f, 10), new Vector3(0, 0, 0)),
            };

            var body = new CompoundBody(bodies, 61);
            body.Position = new Vector3(0, 5, 0);

            _vehicle = new Vehicle(body);

            float wheelOffsetX = 1.5f;
            float wheelOffsetY = 0;
            float wheelOffsetZ = 5;
            float wheelRadius = 1;

            _vehicle.AddWheel(new Wheel(
                                 new RaycastWheelShape(wheelRadius, Matrix.Identity),
                                 new WheelSuspension(2000, 100f, Vector3.Down, .5f, new Vector3(-wheelOffsetX, wheelOffsetY, wheelOffsetZ)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            _vehicle.AddWheel(new Wheel(
                                 new RaycastWheelShape(wheelRadius, Matrix.Identity),
                                 new WheelSuspension(2000, 100f, Vector3.Down, .5f, new Vector3(-wheelOffsetX, wheelOffsetY, -wheelOffsetZ)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            _vehicle.AddWheel(new Wheel(
                                 new RaycastWheelShape(wheelRadius, Matrix.Identity),
                                 new WheelSuspension(2000, 100f, Vector3.Down, .5f, new Vector3(wheelOffsetX, wheelOffsetY, wheelOffsetZ)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            _vehicle.AddWheel(new Wheel(
                                 new RaycastWheelShape(wheelRadius, Matrix.Identity),
                                 new WheelSuspension(2000, 100f, Vector3.Down, .5f, new Vector3(wheelOffsetX, wheelOffsetY, -wheelOffsetZ)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
So no my problem is when I need the collisionshape of the body to be higher, lets say I need a hight of 1 unit. If I increase the height value from 0.5 to 1, the body will "grow" 0.25 upward and 0.25 downward. As the radius of the wheel is 1 the body will touch the ground so that the vehicle can't move anymore. So I need a way to transform the whole body. I tried to set the position of the CompoundShapeEntry which seems to have an influence, but not as I wanted. I also tried to adjust body.CollisionInformation.LocalPosition, but I seems this has only influence on the WorldTransformation (my shape gets rendered with another transformation, but physicaly there as nothing changed). I've also looked at the demo and saw that you adjusted the same properties, but it seems not to work for me.

Please have a look at the attached image, this should make clear what I'm looking for...

Hope you know what I mean and thanks for your great support :P
Attachments
vehicle.png
vehicle.png (15.4 KiB) Viewed 5002 times
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Vehcile + CompoundBody

Post by Norbo »

It seems the easiest thing to do would be to set wheelOffsetY to something such that the wheels are far enough down.
Phippu
Posts: 24
Joined: Fri Jun 03, 2011 3:39 pm

Re: Vehcile + CompoundBody

Post by Phippu »

Thanks for that, I looked everywhere but not there :P sorry my bad :oops:
Post Reply