private void Update() { // Create a ray from the screen point where the mouse is to the scene. Ray ray = cam.ScreenPointToRay(Input.mousePosition); // Check if the left mouse button is held down. if (!Input.GetMouseButton(0)) { Debug.DrawLine(ray.origin, ray.origin + ray.direction * distance); return; } // Check if the ray hit a gameobject with the mesh deformer component. RaycastHit hit; if (Physics.Raycast(ray, out hit, distance)) { MeshDeformer deformer = hit.collider.GetComponent <MeshDeformer>(); if (deformer) { Debug.DrawLine(ray.origin, ray.origin + ray.direction * distance, Color.green); deformer.Deform(hit.point, radius, force); } } else { Debug.DrawLine(ray.origin, ray.origin + ray.direction * distance); } }
public void OnCollisionStay(Collision collision) { if (collision.transform.gameObject.tag == "DeformableMesh") { MeshDeformer meshDeformer = collision.transform.GetComponent <MeshDeformer> (); ContactPoint[] contactPoints = new ContactPoint[collision.contactCount]; collision.GetContacts(contactPoints); foreach (ContactPoint contactPoint in contactPoints) { meshDeformer.Deform(contactPoint.point, 0.5f, 0.05f, -0.5f, -0.05f, Vector3.up); } } }
public void OnCollisionStay(Collision other) { if (other.transform.gameObject.tag == "canDeform") { MeshDeformer meshDeformer = other.transform.GetComponent <MeshDeformer> (); ContactPoint[] contactPoints = new ContactPoint[other.contactCount]; other.GetContacts(contactPoints); foreach (ContactPoint contactPoint in contactPoints) { meshDeformer.Deform(contactPoint.point, 0.1f, 0.05f, -0.1f, -0.05f, Vector3.up); } } Destroy(gameObject, 1); }
void Update() { if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) //TODO what if the collider does not exactly fit the mesh? { MeshDeformer deformer = hit.transform.GetComponent <MeshDeformer>(); if (deformer != null) { deformer.Deform(hit, force); } } } }
void Fire() { Vector3 targetPos = new Vector3(); // Cast a ray out into the scene in the direction of the mouse Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // We only want our ray to collide with layer 9 int layerMask = 1 << 9; if (Physics.Raycast(ray, out hit, layerMask)) { targetPos = (hit.point); } GetComponent <FireController>().Fire(targetPos); // Add a deformation force to our mesh _surfaceMesh.Deform(transform.position, 200.0f); }
public override void TakeDamage(float damage, RaycastHit hit = default(RaycastHit)) { //deform float deformerForce = damage * damageToForceMultiplier; deformerForce = Mathf.Clamp(deformerForce, 0f, maxDeformForce); deformer.deformMethod = MeshDeformer.DeformMethod.InstantOnce; deformer.Deform(hit, deformerForce); //normal take damage if (getShootSound != null && audioSource != null) { audioSource.PlayOneShot(getShootSound); } currentHP -= damage; currentHP = Mathf.Clamp(currentHP, 0f, maxHP); hpBar.UpdateHP(damage); if (currentHP <= 0f) { Die(); } }