More control over chaseCam

so I implemented chase cam and it works perfectly except that sometimes, the camera would follow from BELOW the floor that I have instead of chasing above. this is my code (units are in mm):



[java]

public void enableChaseCam(boolean b, Camera cam, Spatial spatialToFollow) {

if (b == true) {



// Chasecam properties

chaseCam = new ChaseCamera(cam, spatialToFollow, inputManager);

chaseCam.setMaxDistance(1000);

chaseCam.setMinDistance(4000);

chaseCam.setDefaultDistance(8000);

chaseCam.setChasingSensitivity(1f);

chaseCam.setSmoothMotion(true); //automatic following

chaseCam.setUpVector(new Vector3f(0,0,1));

chaseCam.setTrailingEnabled(true);



}

}

[/java]



what can I do to make it follow only above a positive z axis?



thanks

chaseCam.setDownRotateOnCloseViewOnly(true);



I think.

no such thing :S

Ok maybe it’s only in nightlys then.

You could try to restrict its vertical rotation with chaseCam.setMaxVerticalRotation(something) and chaseCam.setMinVerticalRotation(something else). With these values, it should be possible to have the chaseCam only looking from above, not from below.

1 Like

ok fixed it (like u said)… one more question… if I want to disable to the mouse affecting the chaseCam I have enabled [java]chaseCam.setDragToRotate(true)[/java]



but that allows that chaseCam to be moved by dragging the mouse while pressing a button. Is there a way to disable the whole thing? I don’t want the user to be able to change the chaseCam with the mouse in any possible way just let it control itself.



thanks

Not sure, but you could try: [java]chaseCam.setRotationSensitivity(0f);[/java]





Maybe disabling the default flyCam (I think this one will work for sure): [java]flyCam.setEnabled(false);[/java]





or change the trigger for rotation: [java]chaseCam.setToggleRotationTrigger(some trigger);[/java]

1 Like

chaseCam.setToggleRotationTrigger(); did it!!



thanks

You’re welcome! Was the last one I would have tried, but hey, it works :slight_smile:

actually I take it back setting max vertical rotation works in some cases and other cases don’t :S

Well,



Could be anything then. I then have to suggest to either show some of the code or to follow androlos suggestion.


chaseCam.setDownRotateOnCloseViewOnly(true);

I think.


In my Netbeans, I do have this option, so maybe you have to update your SDK?

I was trying to stick to stable and not update because of this single small problem

I don’t update to nightly’s as well, yet I do have the option. So it has to be in JME3 stable?

yeah just updated to that version and still same problem… it doesn’t help

When does the ‘setMaxVerticalRotation’ not work? Maybe it is something in your code. Does the spatial the chasecam is attached to rotate? If so, it could be possible the chasecam rotates with it.

no it happens witn setSmoothMotion is set to true. However I would like to keep it like this because It looks wayyyy nicer with that option on.



as for setMaxVerticalRotation() I can’t seem to figure it out… I feel like I am testing with random numbers which is not the right way to do things. I don’t really understand how it works :S

I used in the past the following to ENABLE the chaseCam to look from below:

[java]chaseCam.setMinVerticalRotation((float)(-0.5*Math.PI)); // Enable the camera to get under the water surface.[/java]



You could try setting the following to prevent the camera from getting below:

[java]chaseCam.setMinVerticalRotation(0f);[/java]

thats exactly what confused me!! it’s set to 0 by default and I set it regardless (in case it changes somewhere else) but that doesn’t help :S

Hmmm, not sure, but do you call cam.update() after this? Just a wild guess…

Made a little testcase which does what you want (at least, I think this is what you want). Rotate with the LMB.



[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.input.ChaseCamera;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.shape.Box;



/**

  • test
  • @author normenhansen

    */

    public class Main extends SimpleApplication

    {

    ChaseCamera chaseCam;

    Node myTarget = new Node();



    public static void main(String[] args)

    {

    Main app = new Main();

    app.start();





    }



    @Override

    public void simpleInitApp()

    {

    Box b1 = new Box(Vector3f.ZERO, 5, 0.01f, 5);

    Geometry geom1 = new Geometry("Box", b1);



    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat1.setColor("Color", ColorRGBA.Red);

    geom1.setMaterial(mat1);

    rootNode.attachChild(geom1);



    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry("Box", b);



    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat.setColor("Color", ColorRGBA.Blue);

    geom.setMaterial(mat);

    myTarget.attachChild(geom);



    rootNode.attachChild(myTarget);



    setCamera();

    }







    public void setCamera()

    {

    flyCam.setEnabled(false);

    chaseCam = new ChaseCamera(cam, myTarget, inputManager);

    cam.update();

    chaseCam.setSmoothMotion(true);

    chaseCam.setDefaultDistance(15f); // Default distance of the camera.

    chaseCam.setMinDistance(0.1f);

    chaseCam.setMaxDistance(50.0f); // Maximum zoom distance of the camera.

    chaseCam.setMaxVerticalRotation((float)Math.PI);

    chaseCam.setMinVerticalRotation((float)Math.PI/2);



    }



    @Override

    public void simpleUpdate(float tpf)

    {

    //TODO: add update code

    }



    @Override

    public void simpleRender(RenderManager rm)

    {

    //TODO: add render code

    }

    }

    [/java]
2 Likes