Different behaviour when adding children directly to Rootnode?

Hi,



I am not sure why this is happening, maybe I am just doing something stupid. I am as many others playing around with creating a car with jme.



At first I just started hacking away and had 1 main class with all the code in, adding all my dynamicphysicnodes to the rootnode. At last I had a little car that worked well enough, so I decided to clean up my code and put everything into neat classes(car, wheel, axles). I did this by extending my classes from Node and adding my DynamicPhysicsNodes to the main class (this.attachChild(dpn)). So something like this was created :



rootNode <- Vehicle(Node) <- chassisNode(DPN)

                                          <-axles(Node) <- Wheels(DPN)



At the end my car is now sliding over the terrain ( just a plain geombox ) instead of the tires gripping like they used to.



So I went and added all the nodes back to rootNode 1 by 1 instead of the little parent <- child tree and voila its back to normal again.



Dunno why this is happening, maybe someone can gimme an idea why ?

Not sure I entirely understood your "diagram": one dpn is child of another? that's not allowed. But it should be working if you have a "normal" node as parent which is not the root node.

sorry :stuck_out_tongue: I will try to explain my little diagram.

key

----

DynamicPhysicsNode = dpn

Node = n

Spatial = s



diagram


rootNode has a child Vehicle
Vehicle (n) has a child chassisNode(dpn) // for physics
                                  chassisNode(dpn) has a child chassisSpatial(Spatial) //for graphics
Vehicle (n) has a child axle(normal Node)  //for front axle
                                                    axle(n) has a child Wheel(n)  //for left wheel
                                                                                  Wheel(n) has a child wheelNode(dpn) //for physics
                                                                                  Wheel(n) has a child wheelSpatial(s) //for graphics
                                                    axle(n) has a child Wheel(n)  //for right wheel
                                                                                  Wheel(n) has a child wheelNode(dpn) //for physics
                                                                                  Wheel(n) has a child wheelSpatial(s) //for graphics
Vehicle (normal Node) has a child axle(n)  //for rear axle
                                                    axle(n) has a child Wheel(n)  //for left wheel
                                                                                  Wheel(n) has a child wheelNode(dpn) //for physics
                                                                                  Wheel(n) has a child wheelSpatial(s) //for graphics
                                                    axle(n) has a child Wheel(n)  //for right wheel
                                                                                  Wheel(n) has a child wheelNode(dpn) //for physics
                                                                                  Wheel(n) has a child wheelSpatial(s) //for graphics

So yes I did not make any dpn's children of other dpn's.

I tested it some more last night. I found that by keeping to the above diagram and only connecting the wheelNode(dpn) of all 4 wheels to the rootNode directly it solves the problem. Im unsure if it has something to do with my physics settings that I make for the wheels being "lost" somehow in the attaching bits.
I only started using jME about 2 weeks ago and this is the first project that I have done sofar, so I might just be doing something uber noobish :P

Though your scene setup does not make much sense :P, it should work. The vehicle and axle nodes will stay at (0,0,0) when you run your simulation (as only their children are moving). Do you by chance move them programmatically?

the way i make the wheels move and the car following is like this :



    private void createJoints()

    {

        final Joint wheelHub = car.ds.getPhysicsSpace().createJoint();

        wheelHub.attach(car.chassisNode, wheelNode);

        wheelHub.setAnchor(pos);

       

        if(canSteer)

        {

            universalJoint = wheelHub.createRotationalAxis();

            universalJoint.setDirection(new Vector3f(0,1,0));

            universalJoint.setPositionMaximum(0.0f);

            universalJoint.setPositionMinimum(0.0f);

        }

       

        wheelAxle = wheelHub.createRotationalAxis();

        wheelAxle.setDirection(new Vector3f(0,0,1));

        if(canSteer)

        {

            wheelAxle.setRelativeToSecondObject(true);

        }

    }



    public void Accelerate(float availableAcceleration, float desiredVelocity, boolean isAccelrating)

    {

        if(isAccelrating)

        {

            wheelAxle.setDesiredVelocity(-desiredVelocity);

            wheelAxle.setAvailableAcceleration(availableAcceleration);

        }

        else

        {

            wheelAxle.setDesiredVelocity(0.0f);

            wheelAxle.setAvailableAcceleration(0.0f);

        }

    }



    public void Steer(boolean isSteering, float min, float max, float force, float steeringWheelPos)

    {

        if(isSteering)

        {

            universalJoint.setPositionMaximum(max);

            universalJoint.setPositionMinimum(min);

            universalJoint.setAvailableAcceleration(force);

            universalJoint.setDesiredVelocity(steeringWheelPos);

        }

        else

        {

            universalJoint.setPositionMaximum(0.0f);

            universalJoint.setPositionMinimum(0.0f);

            universalJoint.setAvailableAcceleration(0.0f);

            universalJoint.setDesiredVelocity(0.0f);

        }

    }





Steer and Accelerate is called from InputAction classes. The car does not have any springs or shock absorbers … just a very plain wheel connected to the chassis by a joint. Otherwise I do not use any other forces or thingies to make the car move ( except the Brake funtion ofcourse :stuck_out_tongue: which is similar to Accelerate just with a higher force and 0 acceleration)

Looks ok to me. Can you reproduce the problem with TestVehicle by adding an intermediate node?

I studied the way that Vehicle works (TestAdvancedVehicle) and its similar to how i have done my classes, only 2 big differences I found was that my wheelBase dpn is part of my wheel class while Vehicle has it in the suspension class. And it seems the weight of my parts are totally different. I tried making a car sorta how i figured the mass of a real car is almost like. Like the chassis weights 1000.0f and the wheels are 50.0f each.



I added a shockAbsorber between my wheelBase and wheel now and got that working. But yeh, I still cant figure out where the problem lies about connecting my wheel node directly to rootNode and it works, and when I connect it to my car structure of nodes the whole car just slides across the ground without any other forces than gravity on it. Could it be something to do with the mass of my car ?



I searched through the forum for car samples and found 1 that connects the wheelNodes directly to rootNode as well, and 1 ( think by a guy named Perrick ) that does it the way Vehicle does it. Both seemed to have based their cars on TestAdvancedVehicle though.



Well, I have gotten another thing that I am trying to do… I want to make my car have weapons similar to the ones used in Robot Wars(tv show and game). So I added a "Piston" on the hood by making 2 dpns(tubelike boxes with one fitting in the other and scaled slightly smaller). I connected the base to the cars chassis with a joint(with no axi) and the inner one to the base with a translationalAxis with a direction vector of (1,0,0). But when my car tilts forward or backwards the inner tube just falls out and keeps going. I have an Anchor on the joint at the base's position. Is there a way i can make it stay in the baseTube until i press a button to make it shoot out, just the difference that i specify in setPositionMaximum and setPositionMinimum? I want to have it retract slowly(maybe based on setDesiredVelocity and setAvailableAcceleration)


I meant TestVehicle (it connect the wheels directly to the chassis) not TestAdvancedVehicle. TestAdvancedVehicle was contributed by perick btw, after he wrote his racing game.



Re your "Piston": use stops on the translational axis to keep the inner box from falling out. Use desiredVelocity and change the stops to let it come out.

ah meh… I put the the stops on backwards :stuck_out_tongue: Now its working after i swopped it min and max values.



Sorry I was trying to compare my vehicle with AdvancedTestVehicle to see if I can find the place where I went wrong as they are made fairly similar. I will spend some time to see if I can figure out what happens if I add some chassis and wheel classes onto TestVehicle.



Thanks for the fast feedback irrisor.

I tried creating the problem with TestVehicle, but with no luck.



I dunno if it is maybe something I dont initialize or set as I am using DebugGameState and not SimplePhysicsGame.



I am rewriting my car classes from scratch atm to clean them up and improve them. Maybe I will come across the problem while doing it.



Ive come across something I am a bit unsure of. I am trying to make a little vehicle building program, with different wheels and whatnot. So when I remove a wheel from a vehicle I destroy it by doing something like the following :



    public void Destroy()

    {

        hubJoint.getAxes().remove(shockAbsorber);

        wheelJoint.getAxes().remove(steerAxle);

        wheelJoint.getAxes().remove(wheelAxle);

       

        shockAbsorber=null;

        steerAxle=null;

        wheelAxle=null;

       

        hubJoint.detach();

        hubJoint=null;

       

        wheelJoint.detach();

        wheelJoint=null;

       

        wheelSpatial.removeFromParent();

        wheelSpatial=null;

       

        wheelNode.removeFromParent();

        wheelNode.detachAllChildren();

        wheelNode.setActive(false);

        wheelNode=null;

       

        hub.removeFromParent();

        hub.detachAllChildren();

        hub.setActive(false);

        hub=null;

    }





At first I didnt have the line : wheelNode.setActive(false);  in there and I could see some physics bits were still not removed and went searching through the forum for a fix. After finding and putting that line in everything seems to be gone.



I have found quite a few posts about people wanting to know how to properly dispose of a physics node and some about disposing spatials. Well, I couldnt find anything that stated it very clear about what exactly I need to do to achieve this, so Im asking the question with my code here to see if someone can maybe give me an answer that is more specificly based on the little bit of code above.



For instance I am unsure if i need to do a : scene.updateGeometricState(0f, true);    after calling wheel.Destroy();


Remove physics node with a call to delete(). (as well as joints, iirc)



You don't need to call updateGeometricStates explicitly as it is called in the game loop anyways.