Chaser camera

I have been following thirdpersoncontroller example.Now I loaded a quake level and instead of the terrain.I set the main camera to 0,0,0 and cube to 0,0,0, But still the camera is looking from above, but the cube is at almost the same level of the model.I need my camera also should look on the same level, where currently the cube is. Please advise me.

@gamerfan said:
I have been following thirdpersoncontroller example.Now I loaded a quake level and instead of the terrain.I set the main camera to 0,0,0 and cube to 0,0,0, But still the camera is looking from above, but the cube is at almost the same level of the model.I need my camera also should look on the same level, where currently the cube is. Please advise me.

mhhh are you using JME3?

no, I am using JME 2.0.

This is the code for your reference,

[java]

/*

  • Copyright © 2003-2009 jMonkeyEngine
  • All rights reserved.

    *
  • Redistribution and use in source and binary forms, with or without
  • modification, are permitted provided that the following conditions are
  • met:

    *
    • Redistributions of source code must retain the above copyright
  • notice, this list of conditions and the following disclaimer.

    *
    • Redistributions in binary form must reproduce the above copyright
  • notice, this list of conditions and the following disclaimer in the
  • documentation and/or other materials provided with the distribution.

    *
    • Neither the name of ‘jMonkeyEngine’ nor the names of its contributors
  • may be used to endorse or promote products derived from this software
  • without specific prior written permission.

    *
  • THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  • "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  • TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  • PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  • CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  • EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  • PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  • PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  • LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  • NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  • SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    */



    package jmeapplication;



    import java.util.ArrayList;

    import java.util.HashMap;

    import java.util.logging.Level;

    import java.util.logging.Logger;



    import javax.swing.ImageIcon;



    import jmetest.terrain.TestTerrain;



    import com.jme.app.SimpleGame;

    import com.jme.bounding.BoundingBox;

    import com.jme.image.Texture;

    import com.jme.input.ChaseCamera;

    import com.jme.input.InputSystem;

    import com.jme.input.ThirdPersonHandler;

    import com.jme.input.joystick.Joystick;

    import com.jme.input.joystick.JoystickInput;

    import com.jme.input.thirdperson.ThirdPersonJoystickPlugin;

    import com.jme.light.DirectionalLight;

    import com.jme.math.FastMath;

    import com.jme.math.Quaternion;

    import com.jme.math.Vector3f;

    import com.jme.renderer.ColorRGBA;

    import com.jme.renderer.Renderer;

    import com.jme.scene.Node;

    import com.jme.scene.Spatial;

    import com.jme.scene.shape.Box;

    import com.jme.scene.state.CullState;

    import com.jme.scene.state.FogState;

    import com.jme.scene.state.TextureState;

    import com.jme.util.TextureManager;

    import com.jme.util.export.binary.BinaryImporter;

    import com.jme.util.resource.ResourceLocatorTool;

    import com.jme.util.resource.SimpleResourceLocator;

    import com.jmex.model.converters.MaxToJme;

    import com.jmex.terrain.TerrainPage;

    import com.jmex.terrain.util.FaultFractalHeightMap;

    import com.jmex.terrain.util.ProceduralTextureGenerator;

    import java.io.BufferedInputStream;

    import java.io.ByteArrayInputStream;

    import java.io.ByteArrayOutputStream;

    import java.io.IOException;

    import java.net.URISyntaxException;

    import java.net.URL;



    /**
  • <code>TestThirdPersonController</code>

    *
  • @author Joshua Slack
  • @version $Revision: 1.21 $

    */

    public class TestThirdPersonController extends SimpleGame {

    private static final Logger logger = Logger

    .getLogger(TestThirdPersonController.class.getName());



    private Node m_character;



    private ChaseCamera chaser;



    private Spatial levelModel = null;



    private float xAngle = ((270.0061119553f-0.35854578f) -1.4610403f) * FastMath.DEG_TO_RAD;



    /**
  • Entry point for the test,

    *
  • @param args

    */

    public static void main(String[] args) {

    try {

    JoystickInput.setProvider(InputSystem.INPUT_SYSTEM_LWJGL);

    } catch (Exception e) {

    logger.logp(Level.SEVERE, TestThirdPersonController.class.toString(),

    "main(args)", "Exception", e);

    }

    TestThirdPersonController app = new TestThirdPersonController();

    app.setConfigShowMode(ConfigShowMode.AlwaysShow);

    app.start();

    }



    /**
  • builds the scene.

    *
  • @see com.jme.app.SimpleGame#initGame()

    */

    @Override

    protected void simpleInitGame() {

    display.setTitle("jME - 3rd person controller test");

    setupLight();

    setupCharacter();

    //setupTerrain();

    setupLevel();

    setupChaseCamera();

    setupInput();

    setupJoystick();

    }



    @Override

    protected void simpleUpdate() {

    chaser.update(tpf);

    System.out.println("…what is the camera : "+cam.getLocation().toString());

    }



    private void setupLight(){

    DirectionalLight dr = new DirectionalLight();

    dr.setEnabled(true);

    dr.setAmbient(new ColorRGBA(5.5f, 0.5f, 0.5f, 1.0f));

    lightState.detachAll();

    lightState.attach(dr);

    }



    private void setupCharacter() {

    Box b = new Box("box", new Vector3f(), 5,5,5);

    b.setModelBound(new BoundingBox());

    b.updateModelBound();

    b.setLocalTranslation(new Vector3f(0.0f,0.0f,0.0f));

    m_character = new Node("char node");

    rootNode.attachChild(m_character);

    m_character.attachChild(b);

    m_character.updateWorldBound(); // We do this to allow the camera setup access to the world bound in our setup code.



    TextureState ts = display.getRenderer().createTextureState();

    ts.setEnabled(true);

    ts.setTexture(

    TextureManager.loadTexture(

    TestThirdPersonController.class.getClassLoader().getResource(

    "jmeapplication/data/texture/Monkey.jpg"),

    Texture.MinificationFilter.BilinearNearestMipMap,

    Texture.MagnificationFilter.Bilinear));

    m_character.setRenderState(ts);

    }





    private void setupChaseCamera() {



    Vector3f targetOffset = new Vector3f();

    targetOffset.y = ((BoundingBox) m_character.getWorldBound()).yExtent * 1.5f;

    cam.setLocation(new Vector3f(0.0f,0.0f,0.0f));

    cam.update();

    chaser = new ChaseCamera(cam, m_character);

    System.out.println("…what is the target Offset value : "+targetOffset);

    // chaser.setTargetOffset(new Vector3f(0.5f,0.5f,24));

    // chaser.setMinDistance(4);

    // chaser.setMaxDistance(18);

    }



    private void setupInput() {

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

    handlerProps.put(ThirdPersonHandler.PROP_DOGRADUAL, "true");

    // handlerProps.put(ThirdPersonHandler.PROP_TURNSPEED, ""+(1.0f * FastMath.PI));

    handlerProps.put(ThirdPersonHandler.PROP_LOCKBACKWARDS, "false");

    handlerProps.put(ThirdPersonHandler.PROP_CAMERAALIGNEDMOVE, "true");

    input = new ThirdPersonHandler(m_character, cam, handlerProps);

    input.setActionSpeed(100f);

    }



    private void setupJoystick() {

    ArrayList<Joystick> joys = JoystickInput.get().findJoysticksByAxis("X Axis", "Y Axis", "Z Axis", "Z Rotation");

    Joystick joy = joys.size() >= 1 ? joys.get(0) : null;

    if (joy != null) {

    ThirdPersonJoystickPlugin plugin = new ThirdPersonJoystickPlugin(joy, joy.findAxis("X Axis"), joy.findAxis("Y Axis"), joy.findAxis("Z Axis"), joy.findAxis("Z Rotation"));

    ((ThirdPersonHandler)input).setJoystickPlugin(plugin);

    chaser.getMouseLook().setJoystickPlugin(plugin);

    }

    }



    private void setupLevel(){

    try {

    ResourceLocatorTool.addResourceLocator(

    ResourceLocatorTool.TYPE_TEXTURE,new SimpleResourceLocator(

    Load3DS.class.getClassLoader().getResource("jmeapplication/data/texture/")));

    ResourceLocatorTool.addResourceLocator(

    ResourceLocatorTool.TYPE_MODEL,new SimpleResourceLocator(

    Load3DS.class.getClassLoader().getResource("jmeapplication/data/texture/")));

    } catch (URISyntaxException e1) {

    e1.printStackTrace();

    }

    MaxToJme converter = new MaxToJme();

    ByteArrayOutputStream BO = new ByteArrayOutputStream();

    URL maxFile = ResourceLocatorTool.locateResource( ResourceLocatorTool.TYPE_MODEL, "ql.3ds");



    try {

    converter.convert(new BufferedInputStream(maxFile.openStream()),BO);

    levelModel = (Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));

    } catch (IOException e) {

    e.printStackTrace();

    }



    levelModel.setLocalScale(2f);

    levelModel.setModelBound(new BoundingBox());

    levelModel.updateModelBound();

    Quaternion quat = new Quaternion();

    quat.fromAngleAxis(xAngle,new Vector3f(1,0,0));

    levelModel.setLocalRotation(quat);

    levelModel.setLocalTranslation(new Vector3f(-60,-7,-33));

    rootNode.attachChild(levelModel);

    }





    }



    [/java]

The issue has been fixed by setting minimum and maximum distance to chase camera.