bool FindVertexToDeformer() { Ray inputRay = new Ray(head.LastPosition, head.transform.forward); RaycastHit hit; if (Physics.Raycast(inputRay, out hit)) { SoftBody deformer = hit.collider.GetComponent <SoftBody> (); if (deformer) { Vector3 dir = (head.transform.position - hit.point).normalized; float dot = Vector3.Dot(head.transform.forward, dir); //Debug.Log ("dot "+dot); if (dot > 0) { int fidx = hit.triangleIndex; Vector3 vertex; int vidx = deformer.FindNearestVertexInTriangle(fidx, hit.point, out vertex); HitPos = hit.point; Debug.LogFormat("FindVertexToDeformer {0}", vidx); head.SetTargetVertex(deformer, vidx); return(true); } } } return(false); }
void HandleInput() { if (Input.GetMouseButtonDown(0)) { Debug.Log("mouse down"); Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(inputRay, out hit)) { SoftBody deformer = hit.collider.GetComponent <SoftBody> (); if (deformer) { int fidx = hit.triangleIndex; Vector3 vertex; int vidx = deformer.FindNearestVertexInTriangle(fidx, hit.point, out vertex); AddFollowForce(deformer, vidx, hit.point + hit.normal * 0.01f); } } } if (Input.GetMouseButtonDown(1)) { Debug.Log("mouse down"); Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(inputRay, out hit)) { FollowForce force = hit.collider.GetComponent <FollowForce> (); if (force) { Destroy(force.gameObject); } } } }