Stalker Posted November 19, 2015 Share Posted November 19, 2015 Hi! In my scene I have multiple instanced robots with single skeleton. When two of them get near enough each they should start shooting lasers. Skeleton has a bone named "Arm.Gun L", its position and orientation already define the origin from where the laser is shot and its direction vector, the problem is that I can't find a way how to access the data. It need to be accessed and copied only once. Find the bone:this._bone = skeletons[0].bones.filter((b: BABYLON.Bone) => { return b.name === "Arm.Gun L";})[0];And when firing:var l = this._laser.createInstance("l");l.position = ? // this._bone.?l.rotation = ? // this._bone.?After looking through the docs for Bone and InstancedMesh (together with its base classes Mesh and Node) the only useful thing I found are local and globalMatrix methods on bones (if I could apply localMatrix to laser would probably do what I want with some minor fixes), but haven't found any efficient way of applying to a laser. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted November 19, 2015 Share Posted November 19, 2015 Look at the matrix.decompose() method, for translation, rotation, & scale breakout. Stalker 1 Quote Link to comment Share on other sites More sharing options...
Stalker Posted November 19, 2015 Author Share Posted November 19, 2015 Didn't really thought using it like this. Smart!Thanks, it works ! Quote Link to comment Share on other sites More sharing options...
Stalker Posted November 19, 2015 Author Share Posted November 19, 2015 If I may bug you for one more thing regarding this...After searching through the forum (problem about rotation), I found out that Bone is presented like a point, so there isn't really any direction in which is facing. I used the code bellow to get rotation, scale and translation.var l = this._laser.clone("l");var s = BABYLON.Vector3.Zero();var r = new BABYLON.Quaternion();var t = BABYLON.Vector3.Zero();this._bone.getWorldMatrix().decompose(s, r, t);l.position.copyFrom(e.position.add(t));l.rotationQuaternion = r.clone();Right is the result in BJS (red thing is added), and left how bone looks like in Blender. In BJS it should be rotated ~90deg by Y axis, so that it's parallel to the gun barrel.That bone is the last one, so I can't use next descendant to calculate direction vector. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.