Camera Node - Gun!

Hey Guys,

I searched for hours now but I still don’t find anything .__. So I have a Terrain with Houses etc…A Physics Player -> CharacterControl and the cam’s Location is set to the physical player location. Now I want to attach a Gun to the screen (basically to the player). But how? With a camera Node I can’t move the view with my mouse anymore…There must be a simple way to do this :open_mouth: Heeeeelp me guys! :slight_smile:

yeh i need this too :slight_smile: also i need gun models too :smiley:

Best way may be to create another viewport. In the following link is a thread about it and with code doing just that.

Other possibilities: application.getGuiNode / tonegodGUI / nifty

Thanks, but the problem is that I don’t know how (where) to attach my gun model. This can’t be so difficult :open_mouth: I mean I could attach it to a node attached to the cam. Then I adjust the rotation and location of the gun. But how can I adjust the rotation of it?

I need this too, if someone find the answer please reply for us. I already look for this since 2 day ago and i didn’t found nothing.


I found this:

But in this case the Object is a Geometry, on my case i got a CharacterControl as my player, a Vector3f as my WalkDirection and a Spatial as my Weapon, so i can’t put both in the same Node.

I created something like this for a ludum dare competition (it was adapted from the CamNode):

Edit: Created a testcase for you guys

[java]package com.mmm.util.test;

import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

public class TestFPSGun extends SimpleApplication {

private Spatial weapon;

public static void main(String[] args) {
    new TestFPSGun().start();

public void simpleInitApp() {

    // Weapon
    Box box = new Box(0.5f, 0.5f, 0.5f);
    weapon = new Geometry("geometry", box);
    Material unshadedMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    // Random thing
    Box box1 = new Box(2, 2, 2);
    Spatial box2 = new Geometry("geometry", box1);
    Material unshadedMat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    unshadedMat1.setColor("Color", ColorRGBA.Blue);

public void simpleUpdate(float tpf) {
    Vector3f vectorDifference = new Vector3f(cam.getLocation().subtract(weapon.getWorldTranslation()));

    Quaternion worldDiff = new Quaternion(cam.getRotation().mult(weapon.getWorldRotation().inverse()));

    // Move it to the bottom right of the screen
    weapon.rotate(0.3f, FastMath.PI, 0);


Edit again: changed color of other box, so you can see easier


I love you! Haha It works :slight_smile:

Thaaaaaaaaaank you!

Works for me too,

Wezrule really thanks :wink:

thank you man! it really works!