public void OnTriggerEnter(Collider other) { if (InputManager.IsUserInput(other)) { if (deform) { Debug.Log("hit"); Vector3 point = GetComponent <Collider>().ClosestPoint(other.transform.position); //point += hit.normal * offset; // need to extract the normal of the laser surface // might be a bit of a hack, create a raycast from the positions of the caller and activator and extract the normal from it Ray ray = new Ray(other.transform.position, this.transform.position); RaycastHit hit; Physics.Raycast(ray, out hit); point += hit.normal * offset; deform.AddDeformForce(point, force); } } }
void Update() { if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // this below is the important part Deformation deform = hit.collider.GetComponent <Deformation>(); if (deform) { Vector3 point = hit.point; point += hit.normal * offset; deform.AddDeformForce(point, force); } } } }