// Update is called once per frame /* * void Update () { * if (Input.GetMouseButton(0)) { * //HandleSlap(); * HandleInputLower(); * } * if (Input.GetMouseButton(1)) { * HandleInputRaise(); * } * } */ void HandleSlap() { Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(inputRay, out hit)) { MeshDeformation deformer = hit.collider.GetComponent <MeshDeformation> (); if (deformer) { Vector3 point = hit.point; point += hit.normal * forceOffset; deformer.AddDeformingForce(point, force); } } }
void HandleInput() { Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(inputRay, out hit)) { MeshDeformation deformer = hit.collider.GetComponent <MeshDeformation>(); //Debug.Log("object: "+ hit.collider.gameObject.name); if (deformer) { //Debug.Log("hit at point: "+ hit.point); Vector3 point = hit.point; point += hit.normal * forceOffset; deformer.AddDeformingForce(point, force); } } }
void AddDeformerTo(GameObject obj, float rayRange) { Vector3 downVec = (-obj.transform.up); float rayDirectionOffsetFromObject = 0.1f; RaycastHit hit; if (Physics.Raycast(obj.transform.position + (downVec * rayDirectionOffsetFromObject), downVec, out hit, rayRange)) { // Use to debug the Physics.RayCast. //Debug.DrawRay(obj.transform.position + (downVec * rayDirectionOffsetFromObject), downVec * rayRange, Color.red); MeshDeformation deformer = hit.collider.GetComponent <MeshDeformation>(); //Debug.Log("object: "+ hit.collider.gameObject.name); if (deformer) { //Debug.Log("hit at point: "+ hit.point); Vector3 point = hit.point; point += hit.normal * forceOffset; deformer.AddDeformingForce(point, force); } } }