public void TryBubl(Vector3 position, int Bubbles) { if (Bubbles > 0 && Random.Range(0f, 1f) < .2f) { ParticleMan.Emit(0, Bubbles, position, Vector3.up); } }
public void GetNearest(Vector3 v, float force, int pieces) { List <Transform> l = new List <Transform>(); if (Forms.Count == 0) { return; } l.AddRange(Forms.OrderBy(x => (x.position - v).magnitude)); int maxN = 0; maxN += Mathf.Max(Forms.FindIndex(x => x == l[0]), maxN); ParticleMan.Emit(4, Random.Range(0, (int)(force / 10f)), v, Vector3.up); for (int i = 0; i < pieces && i < l.Count; i++) { if (l[i].GetComponent <Rigidbody>() != null) { continue; } l[i].parent = null; Forms.RemoveAt(0); RootSegment rs = l[i].gameObject.AddComponent <RootSegment>(); rs.BreakForce = BreakForce; rs.StartVelocity = (l[i].position - v).normalized * Mathf.Clamp(force, 0f, 1f); } Forms = new List <Transform>(); Forms.AddRange(GetComponentsInChildren <Transform>()); CalculateBodyStuff(); }
void OnCollisionEnter(Collision col) { ParticleMan.Emit(0, Random.Range(2, 6), transform.position, col.contacts[0].normal); ParticleMan.Emit(2, Random.Range(1, 4), transform.position, (GetComponent <Rigidbody>().velocity.normalized * .5f + col.contacts[0].normal)); if (col.transform.CompareTag("Destructable")) { _rb.velocity = _oldVelocity * .9f; col.gameObject.GetComponent <DestructableBehaviour>().TakeDamage(col.relativeVelocity.magnitude, col); StartCoroutine(Die()); } else { StartCoroutine(Die()); _lr.widthMultiplier = _lr.widthMultiplier * .7f; if (_canDoyng) { _canDoyng = false; if (col.transform.CompareTag("Statue")) { AudioMan.PlaySound(SoundName.BulletImapct, transform.position); } else { AudioMan.PlaySound(SoundName.Ricochet, transform.position); } } } }
public override void GrabUpdate() { base.GrabUpdate(); ParticleMan.Emit(1, 2, Nozzle.position, Nozzle.forward); for (int i = 0; i < 24; i++) { SudsMaster.TryKillSuds(new Ray(Nozzle.position, Nozzle.forward + new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)) * spread)); } }
void InitComputeShader() { kernelCreateCylinderPsi = CS.FindKernel("CreateCylinderPsi"); kernelInitPsi = CS.FindKernel("InitPsi"); ParticleMan.InitMultiKindKernels(CS, "InitParticles", out kernelInitParticles); CS.SetVector("size", isf.size); int[] res = isf.GetGrids(); CS.SetInts("res", res); CS.SetInts("grids", res); }
void OnCollisionEnter(Collision col) { if (col.transform.CompareTag("Bullet") || col.impulse.magnitude > BreakForce) { if (col.contacts[0].thisCollider.gameObject.name != name) { GetNearest(col.contacts[0].point, col.impulse.magnitude, col.transform.CompareTag("Bullet") ? 8 : 1); ParticleMan.Emit(3, 5, col.contacts[0].point, Vector3.up); AudioMan.PlaySound(SoundName.StoneCrunch, col.contacts[0].point); } } }
public void InitComputeShader() { kernelClamp = new int[(int)GPUThreads.T_KINDS]; ParticleMan.InitMultiKindKernels(CS, "Clamp", out kernelClamp); ParticleMan.InitMultiKindKernels(CS, "InitPsiMask", out kernelInitPsiMask); kernelFlushPsiMask = CS.FindKernel("FlushPsiMask"); kernelInitInkCollisionPsi = CS.FindKernel("InitInkCollisionPsi"); kernelUpdatePsiGlobal = CS.FindKernel("UpdatePsiGlobal"); CS.SetVector("size", isf.size); int[] res = isf.GetGrids(); CS.SetInts("res", res); CS.SetInts("grids", res); }
IEnumerator Boost(Vector3 direction) { _boosting = true; _canBoost = false; float start = Time.time; float fov = _camera.fieldOfView; float normalizeDuration = (Time.time - start) / BoostDuration; while (normalizeDuration < 1) { ParticleMan.Emit(3, 1, _cam.position + _cam.forward, Vector3.up); _rb.velocity = direction.normalized * BoostIntensity.Evaluate(normalizeDuration) * BoostSpeed; _camera.fieldOfView = fov - fov * FovIntensityCurve.Evaluate(normalizeDuration); normalizeDuration = (Time.time - start) / BoostDuration; yield return(null); } Vector3 oldVel = _rb.velocity; oldVel.y = 2; _rb.velocity = oldVel; _boosting = false; }
bool CheckWheel(Wheel w, float angle, bool drive) { Transform t = w.Parent; Vector3 wheelP = t.localPosition; Vector3 oldPosition = t.position; Vector3 oldLocalPosition = t.localPosition; wheelP.y = wheelY; t.localPosition = wheelP; if (drive) { t.transform.localRotation = Quaternion.identity; t.Rotate(Vector3.up, angle); w.SpinDistance += Input.GetAxis($"Vertical_{joystick}") * HorsePower * Time.deltaTime; } w.SpinDistance = Mathf.Clamp(w.SpinDistance, -TopSpinSpeed, TopSpinSpeed); if (Input.GetButton($"Brake_{joystick}")) { w.SpinDistance = TimeScaledMultiply(w.SpinDistance, 1f / BrakeStrength); //body.AddForceAtPosition(forceOnWheel * -pointVelocity.normalized * body.mass * BrakeStrength, t.position); } //Converts wheel speed to spin w.Geo.Rotate(w.Parent.forward, Time.deltaTime * -(180f * w.SpinDistance) / (Mathf.PI * WheelRadius), Space.World); if (Physics.Raycast(t.position + t.up * WheelRadius, -t.up, out RaycastHit hit, WheelRadius * 2f + SuspensionDistance, LayerMask.NameToLayer("Road"))) { Vector3 pointVelocity = body.GetPointVelocity(hit.point); //takes velocity at tire position.... //UP Vector3 normalVelocity = pointVelocity; normalVelocity = Vector3.Project(normalVelocity, t.up) * (((normalVelocity - t.up).magnitude > (normalVelocity - t.up).magnitude) ? -1f : 1f); w.VertSpeed = normalVelocity.magnitude; //SIDE Vector3 speedAgainstTread = Vector3.Project(pointVelocity, w.Parent.forward); w.counterTread = speedAgainstTread; float counterSpeed = speedAgainstTread.magnitude; if (counterSpeed > 6f) { float frameRateMult = 120f * Time.smoothDeltaTime; if (UnityEngine.Random.Range(0f, 2f) > 1f) { ParticleMan.Emit("dust", 1, hit.point, hit.normal); } if (UnityEngine.Random.Range(0f, 3f) > 2f) { ParticleMan.Emit("dirt", Mathf.FloorToInt(frameRateMult * (counterSpeed - 6f) / 2f) + 1, hit.point, hit.normal); } } //FORWARD Vector3 speedWithTread = Vector3.Project(pointVelocity, w.Parent.right); float currentWheelSpeed = (speedWithTread.magnitude * Vector3.Dot(speedWithTread, w.Parent.right)); float suspensionActivation = Mathf.Clamp01((WheelRadius * 2f + SuspensionDistance - hit.distance) / SuspensionDistance); w.SuspensionActivation = suspensionActivation; w.lastForceApplied = suspensionActivation * t.up * SuspensionStrength * body.mass - //upward suspension force normalVelocity * ShockAbsorb - //counteract vertical momentum speedAgainstTread * InertiaAbsorb + //counter skid momentum speedAgainstTread.magnitude * t.right * InertiaReroute + //re-add skid momentum lost to forward direction Mathf.Clamp(w.SpinDistance - currentWheelSpeed, -MaxTorque, MaxTorque) * TireGripStrength * w.Parent.right; float wheelAcceleration = Mathf.Abs(w.SpinDistance - currentWheelSpeed); if (wheelAcceleration > 9f) { float frameRateMult = 120f * Time.smoothDeltaTime; if (UnityEngine.Random.Range(0f, 2f) > 1f) { ParticleMan.Emit("dust", 1, hit.point, hit.normal - t.right); } if (UnityEngine.Random.Range(0f, 3f) > 2f) { ParticleMan.Emit("dirt", Mathf.FloorToInt(frameRateMult * Mathf.Min(MaxTorque / 3f, (wheelAcceleration - 9f) + 1)), hit.point, hit.normal - t.right); } } w.SpinDistance = Mathf.Lerp(w.SpinDistance, currentWheelSpeed, .4f); //Put wheel on the ground t.position = Vector3.Lerp(oldPosition, t.position - transform.up * (hit.distance - WheelRadius * 2f), .2f); w.OnGround = true; return(true); }
// Use this for initialization void OnEnable() { Instance = this; }