I have a SkinnedMeshRender with a mesh and a single bone.
I need to follow a given position on the mesh while it is animated.
I assume I need to apply the bone’s rotation and translation to the point
but I have not a clue how to code it.
Anyone?
I have a SkinnedMeshRender with a mesh and a single bone.
I need to follow a given position on the mesh while it is animated.
I assume I need to apply the bone’s rotation and translation to the point
but I have not a clue how to code it.
Anyone?
Here is what I did:
void Start () {
//Set the start location of the bones
SkinnedMeshRenderer mf = target.GetComponent<SkinnedMeshRenderer>();
s = new Vector3( 0.2f, 4.9f, 199.5f); //This is the known point on the mesh
//The distance from the bone to the given spot on the mesh
distance = Vector3.Distance(mf.bones[0].position, s);
//Create a GameObject to use the LookAt function
GameObject go = new GameObject();
go.transform.position = mf.bones[0].position;
go.transform.LookAt(s);
//Rotation the angle from the bone to the point on the mesh
rotation = go.transform.rotation;
DestroyImmediate(go);
}
void OnDrawGizmos() {
SkinnedMeshRenderer mf = target.GetComponent<SkinnedMeshRenderer>();
bones = mf.bones;
//Mark the start point
Gizmos.color = Color.green;
Gizmos.DrawSphere(s, 0.1f);
//Create a rotation vector from the Quaternion
//Is this right? Not really certain
Vector3 newFwd = rotation * Vector3.forward;
//Create a Ray from the bone in the direction of the point
var ray = new Ray (bones[0].position, newFwd );
//Get the point at the predetermined distance
Vector3 point = ray.GetPoint(distance);
//Draw the point
Gizmos.color = Color.red;
Gizmos.DrawSphere(point, 0.1f);
}
So thats it. Seem to sort of work but doesn’t seem totally accurate.
Any ideas?
Any one?
Any one?
Bueller?