Hello…either I have a lack of understanding of how my code is working or perhaps there is a bug with BabylonJS? Not really sure why…but when I set the rotation of my secondaryWeapon it causes the rotation of the primaryWeapon to be affected. But this does not occur if I manipulate scaling and position of my secondaryWeapon. Everything works as expected actually if I comment out the line that sets the rotation of the secondaryWeapon…but then the issue is I cant rotate my secondaryWeapon. EDIT: After a little more debugging i think my issue actually comes from bakeCurrentTransformIntoVertices(). Either me misunderstanding it…or a bug…not sure. Below is the main function that is causing the issue as well as the other functions that get called by the main function:
async getWeapons() {
// use a service to get my weapons
primaryWeapon = await this.gunService.get('m4', this.scene);
secondaryWeapon = await this.gunService.get('m16', this.scene);
// get the gun in a world position that is good for baking the verticies
primaryWeapon.gunMesh.position = new Vector3(4, -6, 20);
primaryWeapon.gunMesh.scaling = new Vector3(.25, .25, .25);
// make new default 0,0,0 settings so that the gun can rotate 'properly' relative to the camera
this.self.primaryWeapon.gunMesh.bakeCurrentTransformIntoVertices();
// get the gun in a world position that is good for baking the verticies
secondaryWeapon.gunMesh.position = new Vector3(0, 0, 0);
secondaryWeapon.gunMesh.scaling = new Vector3(.02, .02, .02);
secondaryWeapon.gunMesh.rotation = new Vector3(0, 6, 0);
// make new default 0,0,0 settings so that the gun can rotate 'properly' relative to the camera
secondaryWeapon.gunMesh.bakeCurrentTransformIntoVertices();
^^^^EDIT: THIS LINE CAUSES PRIMARY WEAPON ROTATION TO BE CHANGED^^^^^
}
async get(name: String, scene: Scene): Promise<Gun> {
let gun: Gun = this.guns.find(gun => gun.name == name);
await gun.importGunMesh(scene);
return gun;
}
async importGunMesh(scene: Scene): Promise<Mesh> {
this.gunMesh = (await SceneLoader.ImportMeshAsync('', this.gunMeshURL, '', scene)).meshes[0] as Mesh;
this.gunMesh.id = this.name + 'Mesh';
this.gunMesh.name = this.name + 'Mesh';
return this.gunMesh;
}