Please help me with my car..

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Please help me with my car..

Post by Danthekilla »

Im trying to get a car to work...

I have managed after quite a few hours to get a car into the world and some debug rendering to view it. but it doesnt work :( if i throw a box at it ,it collides and moves the car around but i cannot drive it.
I have it on a static tri mesh for my world. I call the accelerate call on it with values of up to 10000000 but nothing happens. but if i throw a box at it i can see the wheels spin around... Oh also the car always seems to flip onto its back as if its completely round...

Also the new licenceing fees seem quite good, this will be my first game using bepu (but my 5th game in total) my previous games have made about $35,000 all up now and i expect this one to make around 15K - 25K and was just wondering do i have to do anything special before the game is released (not for 3 months) or once its out i just contact you and give you your cut? Im just wondering, thats all. I have a team of 4 and we just wanted to know.

Also what new features are coming in the next version? A list of whats to come would be great :)
Anyway i hope you can help me out with my car code its really frustrating...


CODE IS BELOW :

Code: Select all

        
        private List<Wheel> TestWheels;
        private List<Box> TestWheelBodys;
        private Box TestCarBody;
        Vehicle TestCar;

        public MainGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            //Test Car Stuff

            TestCarBody = new Box(g_Camera3D.GET.Position, 1.8f, 0.8f, 3.0f, 40);
            TestWheelBodys = new List<Box>();
            TestWheelBodys.Add(new Box(g_Camera3D.GET.Position, 1, 1, 1, 10));

            Quaternion initialWheelRotation = Quaternion.CreateFromAxisAngle(Vector3.Forward, (float)Math.PI / 2);
            TestWheels = new List<Wheel>();
            //Front left wheel
            TestWheels.Add(new ConvexCastWheel(new Vector3(-3, -0.5, 3.3f), initialWheelRotation, TestWheelBodys[0], 1, new Vector3(0, -1, 0), new Vector3(0, 0, 1), .6f, .7f, .8f, .2f, 2.5f, 1000, .8f));
            //Front right wheel
            TestWheels.Add(new ConvexCastWheel(new Vector3(3, -0.5, 3.3f), initialWheelRotation, TestWheelBodys[0], 1, new Vector3(0, -1, 0), new Vector3(0, 0, 1), .6f, .7f, .8f, .2f, 2.5f, 1000, .8f));
            //Back left wheel
            TestWheels.Add(new ConvexCastWheel(new Vector3(-3, -0.5, -3.3f), initialWheelRotation, TestWheelBodys[0], 1, new Vector3(0, -1, 0), new Vector3(0, 0, 1), .6f, .7f, .8f, .2f, 2.5f, 1000, .8f));
            //back right wheel
            TestWheels.Add(new ConvexCastWheel(new Vector3(3, -0.5, -3.3f), initialWheelRotation, TestWheelBodys[0], 1, new Vector3(0, -1, 0), new Vector3(0, 0, 1), .6f, .7f, .8f, .2f, 2.5f, 1000, .8f));

            TestCar = new Vehicle(TestCarBody, 30,10,TestWheels);
            TestCar.moveTo(new Vector3(0,-100,0));

            space.add(TestCar);

            base.Initialize();
        }

        protected override void LoadContent()
        {
            Model model = Content.Load<Model>("Models/terrain");
            Matrix objecttoworld = Matrix.CreateScale(1f)*Matrix.CreateTranslation(Vector3.Zero);
            g_GameManager.GET.renderManager.SubmitRenderableObject(model, objecttoworld, ObjectVisibility.Rendered | ObjectVisibility.CastShadows, ObjectLifeSpan.Scene);

            //-----------------
            //Create a physical environment from a triangle mesh.
            //First, collect the the mesh data from the model using a helper function.
            //This special kind of vertex inherits from the TriangleMeshVertex and optionally includes
            //friction/bounciness data.
            //The StaticTriangleGroup requires that this special vertex type is used in lieu of a normal TriangleMeshVertex array.
            StaticTriangleGroup.StaticTriangleGroupVertex[] vertices;
            int[] indices;
            StaticTriangleGroup.getVerticesAndIndicesFromModel(model, out vertices, out indices);
            //Give the mesh information to a new TriangleMesh.  
            //TriangleMeshes are internally accelerated structures that 
            //help handle raycasts and various other queries on mesh data.
            TriangleMesh triangleMesh = new TriangleMesh(vertices, indices);
            //Create the StaticTriangleGroup based on the triangle mesh.
            StaticTriangleGroup triangleGroup = new StaticTriangleGroup(triangleMesh) {worldMatrix = Matrix.CreateTranslation(new Vector3(0, 0, 0))};
            //Add it to the space!
            space.add(triangleGroup);
            //-----------------

            TheBox = Content.Load<Model>("Models/blend-deferred/Cube");
            TheBoxMatrix = Matrix.CreateScale(4.0f)*Matrix.CreateTranslation(new Vector3(0.0f, 1f, 0.0f));
        }

        protected override void Update(GameTime in_GameTime)
        {
            TestCar.accelerate(0);
            TestCar.releaseBrake();
            if (g_Controller.GET.IsKeyHeld(Keys.F))
                TestCar.accelerate(7);

            //I have tried without these as well as i assumed that the space update did this...
            TestCar.updateAtEndOfFrame(in_GameTime.ElapsedGameTime.Seconds, 1.0f, in_GameTime.ElapsedRealTime.Seconds);
            TestCar.updateAtEndOfUpdate(in_GameTime.ElapsedGameTime.Seconds, 1.0f, in_GameTime.ElapsedRealTime.Seconds);

            TheBoxMatrix = TestCar.wheels[0].worldMatrix;
            RenderManager.SubmitObject(TheBox, TheBoxMatrix);
            TheBoxMatrix = TestCar.wheels[1].worldMatrix;
            RenderManager.SubmitObject(TheBox, TheBoxMatrix);
            TheBoxMatrix = TestCar.wheels[2].worldMatrix;
            RenderManager.SubmitObject(TheBox, TheBoxMatrix);
            TheBoxMatrix = TestCar.wheels[3].worldMatrix;
            RenderManager.SubmitObject(TheBox, TheBoxMatrix);

            TheBoxMatrix = TestCarBody.worldTransform;
            RenderManager.SubmitObject(TheBox, TheBoxMatrix);

            g_GameManager.GET.space.update(in_GameTime);
            base.Update(in_GameTime);
        }
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Please help me with my car..

Post by Norbo »

I think it might just be the suspension constant. If it is too low, the suspension acts like a wet noodle and can't push the wheels into the ground. The wheel's grip is capped by the normal force (Maximum friction force = friction constant * normal force), so if the normal force is very small, the drive force is very small. Since the car's body is probably dragging on the ground due to the low constant, the collision friction is too much for the drive force to overcome and the car just sits. Try increasing it some (it can go above 1), it should start working better.

I'm not sure what would cause the flipping behavior you mentioned. There is something you should watch out for, though; the wheels' starting positions should be totally contained within the car body. If they aren't, you may find that the wheels sometimes punch through the thin triangle surface and behave nastily, or sometimes when you drive by a wall the wheels will try to 'climb' it, or a variety of other things. By putting some collision such that the initial state of the wheel convex cast is contained, it won't try to climb walls or punch through things as easily. If the wheels need to be far away from the central car body, you can make it a CompoundBody and add a few floating boxes to it that contain the wheels.

You might notice that if the car is flipped and you accelerate, the wheels don't spin. That's because the wheel's spinning behavior is essentially faked. If the wheel has something to roll on, it will appear to spin. This and some other behaviors are things I want to address in a vehicle re-do.

By the way, in the code:

Code: Select all

//I have tried without these as well as i assumed that the space update did this...
TestCar.updateAtEndOfFrame(in_GameTime.ElapsedGameTime.Seconds, 1.0f, in_GameTime.ElapsedRealTime.Seconds);
TestCar.updateAtEndOfUpdate(in_GameTime.ElapsedGameTime.Seconds, 1.0f, in_GameTime.ElapsedRealTime.Seconds);
You were correct in assuming that the space update called those functions automatically, so you can get rid of those lines.

As for the licensing, you just need to send us an e-mail saying you're ready to set up a commercial license at some point before you release the game. We both sign the agreement, and each calendar quarter afterwards, royalties are due. We're currently working on some revised licensing documents, but they should be ready sometime next week if you want to see the actual legal agreement.

The main thing in v0.11.0 is a constraint system overhaul. It includes angular and linear regular constraints, motors, drives, and joint limits. I also want to include a collision response rewrite that could improve collision solving performance by as much as 25% (the real world performance benefit will be less obviously since there's more than just collision solving going on). If there's time, there may also be a "high quality" collision solver that would be about as fast as the current one but would provide greater stability. The rest of the changes are generally minor.

As I briefly mentioned before, there's also a vehicle redo on the todo list. It probably won't make it into v0.11.0, but the main goal will be making it easier to use (less massive-parameter-list constructors) while supporting more advanced behavior by considering wheels to be semi-physical.
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Re: Please help me with my car..

Post by Danthekilla »

Thank you very much

The weird flipping was because i had the wheels far away from the body (I thought a wider wheelbase would make it more stable)
And i also had to up the spring constant.

if you could send me a copy of the new licence/legal agreement when you have it ready i would like to look it over.
well from what i have seen in the last week from my playing around with bepu it looks quite good and solid i can't wait for .11 however as im having a bit of trouble making a ragdoll with the current system (ill probably get there) Is there any ballpark for when .11 will be ready? weeks, months, a year? It would be good to know because as i said our game is going to take 3-4 months to make and we would like to plan early for any new versions of bepu.

Anyway thanks again with the car :)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Please help me with my car..

Post by Norbo »

Sure, I'll send a copy when it's ready.

v0.11.0 should be out no later than late February. If it comes to it, lower priority pieces will be pushed to v0.12.0 to make this happen.
Post Reply