The Chase Camera

Hi guys, I'm having problems with a camera. I just want a camera to follow a box with this method :



    private void buildChaseCamera() {
        Vector3f targetOffset = new Vector3f();
        targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 1.5f;
        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, player, props);
        chaser.setMaxDistance(8);
        chaser.setMinDistance(2);
    }



Code from : The Chase Camera

Trying this way i'm getting a null pointer expection in this line :
targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 1.5f;

I can't understand it. Any fast idea? I will appreciate any tip.
Edit: variables targetOffset(Vector3f) and player are ok.

Seems that the WorldBound is null. You need to set boundings on nodes / spatials. This is important for culling and for collisions.



Try this (written from memory, methods can be namend differently):


player.setModelBound(new BoundingBox());
player.updateModelBounds();


before you try to do sth with the worldbound.

Regards
jme1133 said:


Trying this way i'm getting a null pointer expection in this line :
targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 1.5f;

I can't understand it. Any fast idea? I will appreciate any tip.
Edit: variables targetOffset(Vector3f) and player are ok.


If you call updateWorldBound() on your chased node it works

It works. Mmm… ok, now it's time to read about spatial and nodes.

Thank you guys.  :slight_smile: