/// <summary> /// Create a particle effect and play an impact sound for this surface being hit by a bullet /// </summary> public static Particles DoBulletImpact(this Surface self, TraceResult tr) { // // No effects on resimulate // if (!Prediction.FirstTime) { return(null); } // // Drop a decal // var decalPath = Rand.FromArray(self.ImpactEffects.BulletDecal); if (decalPath != null) { if (DecalDefinition.ByPath.TryGetValue(decalPath, out var decal)) { decal.PlaceUsingTrace(tr); } } // // Make an impact sound // if (!string.IsNullOrWhiteSpace(self.Sounds.Bullet)) { Sound.FromWorld(self.Sounds.Bullet, tr.EndPos); } // // Get us a particle effect // string particleName = Rand.FromArray(self.ImpactEffects.Bullet); if (particleName == null) { particleName = Rand.FromArray(self.ImpactEffects.Regular); } if (particleName != null) { var ps = Particles.Create(particleName, tr.EndPos); ps.SetForward(0, tr.Normal); return(ps); } return(default);
private void UpdateBody(Entity ent, PhysicsBody body) { var waterDensity = 1000; var oldLevel = body.WaterLevel; var density = body.Density; var waterSurface = WaterEntity.WorldPos; var bounds = body.GetBounds(); var velocity = body.Velocity; var pos = bounds.Center; pos.z = waterSurface.z; var densityDiff = density - waterDensity; var volume = bounds.Volume; var level = waterSurface.z.LerpInverse(bounds.Mins.z, bounds.Maxs.z, true); body.WaterLevel = level; if (ent.IsClientOnly == Host.IsClient) { var bouyancy = densityDiff.LerpInverse(0.0f, -300f); bouyancy = MathF.Pow(bouyancy, 0.1f); // DebugOverlay.Text( pos, $"{bouyancy}", Host.Color, 0.1f, 10000 ); if (bouyancy <= 0) { body.GravityScale = 1.0f - body.WaterLevel * 0.8f; } else { var point = bounds.Center; if (level < 1.0f) { point.z = bounds.Mins.z - 100; } var closestpoint = body.FindClosestPoint(point); float depth = (waterSurface.z - bounds.Maxs.z) / 100.0f; depth = depth.Clamp(1.0f, 10.0f); //DebugOverlay.Text( point, $"{depth}", Host.Color, 0.1f, 10000 ); //DebugOverlay.Line( point, closestpoint, 1.0f ); //body.ApplyImpulseAt( closestpoint, (Vector3.Up * volume * level * bouyancy * 0.0001f) ); body.ApplyForceAt(closestpoint, (Vector3.Up * volume * level * bouyancy * 0.05f * depth)); //body.ApplyImpulseAt( ) body.GravityScale = 1.0f - MathF.Pow(body.WaterLevel.Clamp(0, 0.5f) * 2.0f, 0.5f); } body.LinearDrag = body.WaterLevel * WaterThickness; body.AngularDrag = body.WaterLevel * WaterThickness * 0.5f; } if (Host.IsClient) { if (oldLevel == 0) { return; } var change = MathF.Abs(oldLevel - level); //Log.Info( $"{change}" ); if (change > 0.001f && body.LastWaterEffect > 0.2f) { if (oldLevel < 0.3f && level >= 0.35f) { var particle = Particles.Create("particles/water_splash.vpcf", pos); particle.SetForward(0, Vector3.Up); body.LastWaterEffect = 0; Sound.FromWorld("water_splash_medium", pos); } if (velocity.Length > 2f && velocity.z > -10 && velocity.z < 10) { var particle = Particles.Create("particles/water_bob.vpcf", pos); particle.SetForward(0, Vector3.Up); body.LastWaterEffect = 0; } } } }