Attach a camera behinde the car in TestAdvancedVehicle

I read that the camnode have the problem in the jmephysics, it's true?

I have testet the TestAdvancedVehicle and I start to develop a car games.

I would use a camera that have a visual such tipical auto games.

What is the solution?

In this example the code of camera is

    input.removeFromAttachedHandlers( cameraInputHandler );

        cameraInputHandler = new ChaseCamera( cam, car.getChassis().getChild( 0 ) );

      input.addToAttachedHandlers( cameraInputHandler );

I wolud disable the rotation by mouse, in brief have the tipical near visual fo the car games.

I'm sorry of my bad english.

matant2 said:

I read that the camnode have the problem in the jmephysics, it's true?

The ChaseCamera has a problem with low framerates (not with physics). The CameraNode should work fine anywhere.

someone can post a code to insert  in TestAdvancedVehicle to create a camera that  follow the car in the typcal visual of games auto, and also disable the rotation of camera and the input from the mouse?

I have attempted but don't have finded a solution!

Create this method on the TestAdvancedVehicle class:

    protected void simpleUpdate() {
       // first set the camera location same as car's
       // Now get it a bit away from the car in the X axis...
       // Then, let's get it over the car just a bit as well...

       // Now, tell the camera to look at the car:
       cam.lookAt(car.getChassis().getChild(0).getWorldTranslation(), Vector3f.UNIT_Y);

I think is right... Tweek it a bit...

And, of course, with this code you can GET RID of the ChaseCamera completelly by commenting out these lines at the initInput() method:

//cameraInputHandler = new ChaseCamera( cam, car.getChassis().getChild( 0 ) );
//input.addToAttachedHandlers( cameraInputHandler );

Of course, with this code, I'll get some flickering because of the lack of sync between physics and camera updates... To get rid of it you'll have to put the above code inside a PhysicsCallback update...

Perik thanks thanks thanks,

Where i find documentation about PhysicsCallback ???

Perik, Only you save me with dirty racers!

I have finded a short line of code about PhysicCallBack in aircarrier.

But what is PhysicsWorld?

And why my project dont' find the import com.jmex.physics.PhysicsWorld;

PhysicsWorld is from jmephysics 0.4. You are most probably using jME Physics 2. PhysicsSpace is the 'world' and PhysicsUpdateCallback is probably what perick meant. But it's not suited in this case. Because you don't need to update the camera each simulation step, but after each call to PhysicsSpace.update. This means you need to do it once before rendering only. If you are using SimpleGame you can achieve this by adding the update call for the camera into simpleRender instead of simpleUpdate.

thanks irrisor ! work perfectly!

the last question…the movement of the camera because that have a fixed position respect the car, it's difficult make it soft in the movement, i have thinked a set of if instruction that if the spedd car is slowly the camera is more near? This is the right street?

Still Thanks for the answer on  previous question!

The best way to do "inertia" movements of the camera is to use the implemented ChaseCamera…:slight_smile: You can enable/disable a lot of features, like ACCENT, ROLL and ROTATION by tweeking the parameters. Take a better look at its examples…

Edit: Since you're trying to learn some stuff, maybe it'd be nice to test some ideas you have. Feel free to ask any question regarding the related APIs, math functions and utility methods (those found in Quaternion, Vector3f, etc).

the problem is exactly find example and exhaustive documentation.

can you repost the code of chasecamera? Perik.

Perik, when you repost the code of dirtyracer.

I prefer to learn by example. 

perick can you help me to modify this chasecamera?

    private void buildChaseCamera() {

        Vector3f targetOffset = new Vector3f();

        targetOffset.y = ((BoundingBox) car.getChassis().getChild(0).getWorldBound()).yExtent * 2f;

        targetOffset.z = ((BoundingBox) car.getChassis().getChild(0).getWorldBound()).zExtent * -1f;

        targetOffset.x = ((BoundingBox) car.getChassis().getChild(0).getWorldBound()).xExtent * -1f;

        HashMap<String, Object> props = new HashMap<String, Object>();

      props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "6");

        props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "3");

        props.put(ThirdPersonMouseLook.PROP_MAXASCENT, ""+45 * FastMath.DEG_TO_RAD);

        props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(5, 0, 30 * FastMath.DEG_TO_RAD));

        props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);

        chaser = new ChaseCamera(cam, car.getChassis().getChild(0), props);




it's have a strange movement, and i cannot positioned it behind the car, and disable the mouse

ok perick, i have used your code from tankebattle, the only problem is to disable the roation by mouse.

When you repost the dirty race code? do this benevolence for me!

it's have a strange movement

What do you mean?? On OSX the testAdvancedVehicle the chasecamera goes nuts for me,  which is really weird since all the other tests run at almost 300fps.  The fps does drop to less than 10fps, but so far no one has been able to point me in a solution vector.  On my windows (virtual machine with crappy virtual 16MB gfx card) it runs fine at almost 60FPS; however my real hardware is a dual core 2 GHZ, 2BG RAM, 256 MB ATI x1600.  So that hardware should be more than sufficient to run ANY of the tests, kinda makes me think there is an underlying issue still.

Also find the ChaseCamera goes nuts initially. Not sure what hevee did, but his chase camera worked really nicely


I use OSX as well and TestAdvancedVehicle goes fine at over 150FPS on my crappy intel IGP GMA950 (macbook).

Did you try to profile and find the bottleneck basixs?

no, but thanx for the feedback. :slight_smile:

I guess the problem must be here, I have no idea what though…