ChaseCamera and PhysicsControl ( Solved )

Hi,

I’m trying to use the ChaseCamera.

But, unlike the project TestCameraMotionPath, the spatial I’m targetting has a physicsControl.

I do something like this :

[java]

public void init()

{

[…]

this.chaser = new ChaseCamera( cam, inputManager );

this.chaser.setSmoothMotion(true);

this.chaser.setMaxDistance(10.0f);

this.chaser.setDefaultDistance(3.0f);

[…]

}

private void changeSelection( SceneCharacter sceneCharacter )

{

Spatial spatial = null;

if( sceneCharacter != null )

spatial = sceneCharacter.getSpatial(); // The problem is here I think : I think I need to change it to sceneCharacter.getPhysicsControl().get???

chaser.setSpatial( spatial );

if( chaser.isEnabled() )

{

if( spatial == null )

{

chaser.setEnabled( false );

flyCam.setEnabled( true );

}

else

flyCam.setEnabled( true );

}

else if( flyCam.isEnabled() )

{

if( spatial != null )

{

flyCam.setEnabled( false );

chaser.setEnabled( true );

}

else

chaser.setEnabled( false );

}

}

[/java]

My camera is not following my character, and its position is completly messed up.

( That’s the first time I try to use a ChaserCamera. There may be some things I have completly overlooked )

Is it the correct way to do it ?

Thanks in advance

No, the chase camera is a control, don’t use the setSpatial on it because it’s called internally

use spatial.setControl(chaser).

You can do it in the init method btw



you can look at the TestWalkingChar to an example of chase camera on a physics character.

btw the TestCameraMotionPath does not use the chase camera, it moves the cam over a spline path.

If I understand correctly what is done in the TestCameraMotionPath; the chase camera is used ad long as you don’t trigger the launch of the MotionPath.

Well, if the TestWalkingChar use it too, I will look at it :slight_smile:



The fact the the ChaseCamera is a Control helped me greatly. Thanks !



My problem is nearly solved;

It was as follow : I wanted to be change the target of my ChaseCamera ( Since I didn’t know how to delete it )

Now I use something like this :

[java]

private void changeSelection( SceneCharacter sceneCharacter )

{

Spatial newSpatial = null;

if( sceneCharacter != null )

newSpatial = sceneCharacter.getSpatial();





if( currentChasedSpatial != newSpatial )

{

if( currentChasedSpatial != null )

currentChasedSpatial.removeControl( chaser );



currentChasedSpatial = newSpatial;

initChaser();

updateCamera();

}

}



private void initChaser( )

{

// Remove last listening

if( this.chaser != null )

inputManager.removeListener( chaser );



// New chaser

if( currentChasedSpatial == null )

this.chaser = new ChaseCamera( cam );

else

this.chaser = new ChaseCamera( cam, currentChasedSpatial );



this.chaser.setSmoothMotion( true );

this.chaser.setMaxDistance(100.0f);

this.chaser.setDefaultDistance(20.0f);



//Custom mappings

//


[...]
}

private void updateCamera()
{
if( moving )
{
camNode.getControl(0).setEnabled( true );
chaser.setEnabled( false );
flyCam.setEnabled( false );
}
else
{
camNode.getControl(0).setEnabled( false );
if( currentChasedSpatial == null )
{
chaser.setEnabled( false );
flyCam.setEnabled( true );
}
else
{
flyCam.setEnabled( false );
chaser.setEnabled( true );
}
}
}
[/java]

It's working but I have a still problem with my vertical axis.
Is it possible to set the Up axis so that I can rotate around the currentChasedSpatial while conserving the Up axis ?

Is it the chaseCam that rotates the cam like that?

Yes. it seems it is.



Here is a screen before I call the method changeSelection()

I can’t reproduce your issue, but anyway this feature would be useful.

I added a setUpVector on the chaseCamera in last revision.

Try to use it when switching spatials.

Ok, thanks !

I will try to get the next Nightly build :slight_smile: ( For now, I can’t. Seems like the server is too busy )

Edit :

By the way, is there some alternate mirror servers for the nightly builds? ( I havn’t been able to dwonload a build the past week )



Perfect, it works !