internal void Detonate() { if (_detonated || !_useDetonation) { return; } _detonated = true; bool showBaseEffect = true; if (_detonationSurfaceResponse != null && _currentCollision != null) { RaycastHit raycastHit = RaycastContact(_currentCollision.contacts[0]); SurfaceResponse.ResponseEffect responseEffect = GetResponseEffect(raycastHit, _detonationSurfaceResponse); if (responseEffect != null) { showBaseEffect = !responseEffect.disableBaseEffect; CreateEffect(responseEffect.castable, raycastHit); } } if (showBaseEffect && _detonationCastable != null) { _detonationCastable.SetCaster(_caster); CreateEffect(_detonationCastable, this.transform.position, this.transform.rotation); } Destroy(this.gameObject); }
protected void Tumble(ContactPoint contactPoint, SurfaceResponse surfaceResponse) { if (Time.time < _nextTumbleTime) { return; } if (surfaceResponse == null) { return; } // Raycast to contact point RaycastHit raycastHit = RaycastContact(contactPoint); // Determine if there is a response effect SurfaceResponse.ResponseEffect responseEffect = surfaceResponse.GetResponseEffect(raycastHit, _rigidbody.velocity.magnitude); if (responseEffect == null) { return; } // Create effect, apply dynamics CreateEffect(responseEffect.castable, raycastHit); ApplyResponseDynamics(responseEffect, raycastHit); // Define the next time that the tumblable is allowed to tumble SetNextTumbleTime(); }
protected SurfaceResponse.ResponseEffect GetResponseEffect(RaycastHit raycastHit, SurfaceResponse surfaceResponse) { // Determine if there is a surface response if (surfaceResponse == null) { return(null); } // Determine if there is a response effect SurfaceResponse.ResponseEffect responseEffect = surfaceResponse.GetResponseEffect(raycastHit, _relativeImpactVelocity.magnitude); if (responseEffect == null) { return(null); } return(responseEffect); }
protected void ApplyResponseDynamics(SurfaceResponse.ResponseEffect responseEffect, RaycastHit raycastHit) { if (responseEffect.stick) { StickTo(raycastHit.collider.gameObject); return; } if (responseEffect.bounciness != 0) { _rigidbody.velocity += (_relativeImpactVelocity.magnitude * responseEffect.bounciness) * raycastHit.normal; } // _rigidbody.velocity += Vector3.Reflect(-_relativeImpactVelocity, raycastHit.normal) * responseEffect.bounciness; _rigidbody.AddForce(raycastHit.normal * responseEffect.force, responseEffect.forceMode); float frictionScale = 1f - responseEffect.friction; _rigidbody.velocity *= frictionScale; _rigidbody.angularVelocity *= frictionScale; }
protected virtual void Impact(RaycastHit raycastHit) { if (_stuck) { return; } // Determine if there is a collider to the raycast if (raycastHit.collider == null) { return; } // Define lightmap color Color lightmapColor = LightmapHelper.GetColor(raycastHit); // Create effects SurfaceResponse.ResponseEffect responseEffect = GetResponseEffect(raycastHit, _impactSurfaceResponse); //Impactable impactable = raycastHit.collider.GetComponent<Impactable>(); //if(impactable != null) // impactable.SetCaster(_caster); bool showBase = true; // Apply physics dynamics if (responseEffect != null) { CreateEffect(responseEffect.castable, raycastHit); ApplyResponseDynamics(responseEffect, raycastHit); showBase = !responseEffect.disableBaseEffect; } if (showBase) { CreateEffect(_impactBase, raycastHit); } }