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 Heeeeelp me guys!
Thanks, but the problem is that I don’t know how (where) to attach my gun model. This can’t be so difficult 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?
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.
public class TestFPSGun extends SimpleApplication {
private Spatial weapon;
public static void main(String[] args) {
new TestFPSGun().start();
}
@Override
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");
weapon.setMaterial(unshadedMat);
rootNode.attachChild(weapon);
// 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);
box2.setMaterial(unshadedMat1);
rootNode.attachChild(box2);
}
public void simpleUpdate(float tpf) {
Vector3f vectorDifference = new Vector3f(cam.getLocation().subtract(weapon.getWorldTranslation()));
weapon.setLocalTranslation(vectorDifference.addLocal(weapon.getLocalTranslation()));
Quaternion worldDiff = new Quaternion(cam.getRotation().mult(weapon.getWorldRotation().inverse()));
weapon.setLocalRotation(worldDiff.multLocal(weapon.getLocalRotation()));
// Move it to the bottom right of the screen
weapon.move(cam.getDirection().mult(3));
weapon.move(cam.getUp().mult(-0.8f));
weapon.move(cam.getLeft().mult(-1f));
weapon.rotate(0.3f, FastMath.PI, 0);
}
}[/java]
Edit again: changed color of other box, so you can see easier