void OnCollisionStay(Collision collision) { foreach (var contact in collision.contacts) { deformableMesh.AddDepression(contact.point, collisionRadius); } }
private void OnCollisionStay(Collision collision) { if (collision.collider.gameObject.layer != 8) { return; } foreach (var contact in collision.contacts) { deformableMesh.AddDepression(contact.point, collision.collider.bounds.extents.x / 8); } particleManager.PlayParticleAtLocation(collision.GetContact(0).point); }
// Update is called once per frame void Update() { //Debug.Log(initRaycastPoint.transform.forward); // Debug.Log(Vector3.Distance(initRaycastPoint.position, prevPos)); Vector3 diff = initRaycastPoint.position - prevPos; prevPos = initRaycastPoint.position; /*for(int i =1; i < divisionNumber; i++) * { * * foreach (Vector3 pos in rayCastPos) * { * RaycastHit hit; * Ray ray = new Ray(initRaycastPoint.position + pos - (diff / divisionNumber * i), Vector3.down); * //Debug.DrawRay(initRaycastPoint.position + pos, Vector3.down, Color.red, 1f); * if (Physics.Raycast(ray, out hit, 0.3f)) * { * float deformRate = 1 - (Vector3.Distance(initRaycastPoint.position, initRaycastPoint.position + pos) / rayCastFieldRadius); * deformableMesh.AddDepression(hit.triangleIndex, deformRate); * } * } * }*/ Vector3 diffNorm = diff.normalized; int index = 0; while (diff.magnitude > (diffNorm * deltaRate * index).magnitude) { foreach (Vector3 pos in rayCastPos) { RaycastHit hit; Ray ray = new Ray(initRaycastPoint.position + pos - diff + diffNorm * deltaRate * index, Vector3.down); //Debug.DrawRay(initRaycastPoint.position + pos, Vector3.down, Color.red, 1f); if (Physics.Raycast(ray, out hit, 0.3f)) { float deformRate = 1 - (Vector3.Distance(initRaycastPoint.position, initRaycastPoint.position + pos) / rayCastFieldRadius); deformableMesh.AddDepression(hit.triangleIndex, deformRate); } } index++; } }