I have been working on adding automatic fire to the Walking Character test. All is working good except I am a little confused on how to change where the bullets are coming from. I used the world location of the gun…but it’s using the origin of the gun…I was hoping that I could do something like
Vector3f gunWorldPos = gunNode.getWorldTranslation();
Vector3f bulletPos = gunWorldPos.addLocal(0f,0f,0f); // values put in to change location
however, I can’t seem to get it lined up correctly and my bullets end up flying in a weird direction… am I not using the correct method to do this?
here’s what my code for BulletControl looks like so far…
[java] private void bulletControl() {
shootingChannel.setAnim(“Dodge”, 0.1f);
shootingChannel.setLoopMode(LoopMode.Loop);
Geometry bulletg = new Geometry(“bullet”, bullet);
bulletg.setMaterial(matBullet);
bulletg.setShadowMode(ShadowMode.CastAndReceive);
//bulletg.setLocalTranslation(character.getPhysicsLocation().add(cam.getDirection().mult(5)));
Vector3f gunWorldPos = gunNode.getWorldTranslation();
Vector3f bulletPos = gunWorldPos.addLocal(0f,0f,0f);
//bulletg.setLocalTranslation(new Vector3f(gunWorldPos));
bulletg.setLocalTranslation(new Vector3f(bulletPos));
RigidBodyControl bulletControl = new BombControl(bulletCollisionShape, 1);
bulletControl.setCcdMotionThreshold(0.1f);
bulletControl.setLinearVelocity(cam.getDirection().mult(80));
bulletg.addControl(bulletControl);
rootNode.attachChild(bulletg);
getPhysicsSpace().add(bulletControl);
}[/java]
@ca1015 said:
Vector3f gunWorldPos = gunNode.getWorldTranslation();
Vector3f bulletPos = gunWorldPos.addLocal(0f,0f,0f); // values put in to change location
Never directly modify the results of a getWorldTranslation(), getLocalTranslation(), etc. It messes things up and the object will just ignore it in some cases anyway.
Always setLocalTranslation() instead. You cannot forcefully set the world translation of an object directly... I don't even know what that means in a scene graph actually.