Hello still the same game but another problem.
Now I want to rotate the tank canon to the mouse coordinates. I already have to position of the mouse in the "game" coordinates. I only need an idea how to rotate the canon.
Here is the code of my tank. It has a rotation axis between the down part (wheels) and the rotator (conduit).
tank = pS.createDynamicNode();
canon = pS.createDynamicNode();
rootNode.attachChild(canon);
rootNode.attachChild(tank);
Box tankname = new Box( tankName, new Vector3f(), 0.35f, 0.3f, 0.3f );
Box rotater = new Box("rotater", new Vector3f(), 0.1f, 0.025f, 0.1f );
// Tank down part
tank.attachChild( tankname );
playerLeftPart = tank.createBox( "left" );
playerLeftPart.getLocalTranslation().set( 0, 0, 0.15f );
playerLeftPart.getLocalScale().set( 0.7f, 0.6f, 0.3f );
playerRightPart = tank.createBox( "right" );
playerRightPart.getLocalTranslation().set( 0, 0, -0.15f );
playerRightPart.getLocalScale().set( 0.7f, 0.6f, 0.3f );
tank.getLocalTranslation().set( currentPosition );
// Rotator and aim
canon.attachChild(rotater);
playerRotatorPart = canon.createBox("up");
playerRotatorPart.getLocalTranslation().set( 0, 0, 0.0f );
playerRotatorPart.getLocalScale().set( 0.2f, 0.05f, 0.2f );
Vector3f tmp = new Vector3f(currentPosition.clone());
canon.getLocalTranslation().set( tmp.x + 0.15f, tmp.y + 0.325f, tmp.z );
Box shooter = new Box("shooter", new Vector3f(), 0.3f, 0.075f, 0.075f );
shooter.setLocalTranslation(0.25f, 0.1f, 0.0f);
canon.attachChild(shooter);
playerShoter = canon.createBox("up");
playerShoter.getLocalTranslation().set( 0.25f, 0.1f, 0.0f );
playerShoter.getLocalScale().set( 0.6f, 0.15f, 0.15f );
// Collision Group
Random r = new Random(System.currentTimeMillis());
cgTank = pS.createCollisionGroup("tankCG" + r.nextInt());
tank.setCollisionGroup(cgTank);
cgTank.collidesWith(cgTank, false);
canon.setCollisionGroup(cgTank);
// Joints
joint_tank_canon = pS.createJoint();
// attach to joins
joint_tank_canon.attach(canon,tank);
//axis
rotAxis = joint_tank_canon.createRotationalAxis();
//freedoms
rotAxis.setDirection(new Vector3f(0,1,0));
rotAxis.setAvailableAcceleration(70);
I am able to move the conduit by pressing a key and using the function
rotAxis.setDesiredVelocity(3);
//or
rotAxis.setDesiredVelocity(-3);
But I do not want to move the conduit key. Would be nice to do it with the mouse position.
(So the conduit follows the mouse movement). Can someone help me?
With kind regards
Ineluki