public virtual void ShootBullet(float spread, float force, float damage, float bulletSize, string impactEffect = null, DamageFlags damageType = DamageFlags.Bullet) { Vector3 forward = Owner.EyeRotation.Forward; forward += (Vector3.Random + Vector3.Random + Vector3.Random + Vector3.Random) * spread * 0.25f; forward = forward.Normal; foreach (TraceResult trace in TraceBullet(Owner.EyePosition, Owner.EyePosition + forward * BulletRange, bulletSize)) { Vector3 endPos = trace.EndPosition + trace.Direction * bulletSize; if (string.IsNullOrEmpty(impactEffect)) { trace.Surface.DoBulletImpact(trace); } else { Particles.Create(impactEffect, endPos)?.SetForward(0, trace.Normal); } if (!IsServer || !trace.Entity.IsValid()) { continue; } using (Prediction.Off()) { DealDamage(trace.Entity, trace.EndPosition, forward * 100f * force, damage, damageType, trace); } } }
private void UpdateGrab(UserInput input, Vector3 eyePos, Rotation eyeRot, Vector3 eyeDir, bool wantsToFreeze) { if (wantsToFreeze) { heldBody.BodyType = PhysicsBodyType.Static; if (GrabbedEntity.IsValid()) { var freezeEffect = Particles.Create("particles/physgun_freeze.vpcf"); freezeEffect.SetPos(0, heldBody.Transform.PointToWorld(GrabbedPos)); } GrabEnd(); return; } MoveTargetDistance(input.MouseWheel * TargetDistanceSpeed); bool rotating = input.Down(InputButton.Use); bool snapping = false; if (rotating) { EnableAngularSpring(input.Down(InputButton.Run) ? 100.0f : 0.0f); DoRotate(eyeRot, input.MouseDelta * RotateSpeed); snapping = input.Down(InputButton.Run); } else { DisableAngularSpring(); } GrabMove(eyePos, eyeDir, eyeRot, snapping); }
public override void Spawn() { SetModel("models/tank_rocket.vmdl"); timeSinceLaunched = 0; Transmit = TransmitType.Always; Tags.Add("rocket"); using (Prediction.Off()) { TrailEffect = Particles.Create("particles/rocket_trail.vpcf"); TrailEffect.SetEntity(0, this, CollisionBounds.Mins.WithZ(0).WithY(0)); } Light = new SpotLightEntity { Position = Position + Rotation.Forward * (CollisionBounds.Mins.x - 1), Rotation = Rotation.LookAt(Rotation.Backward), DynamicShadows = true, Color = new(1, 0.5f, 0), Brightness = 2, Parent = this, Range = 96, InnerConeAngle = 15, OuterConeAngle = 70 }; //timeAlive = Rand.Float(); }
private void UpdateGrab(Vector3 eyePos, Rotation eyeRot, Vector3 eyeDir, bool wantsToFreeze) { if (wantsToFreeze) { if (heldBody.BodyType == PhysicsBodyType.Dynamic) { heldBody.BodyType = PhysicsBodyType.Static; } if (GrabbedEntity.IsValid()) { var freezeEffect = Particles.Create("particles/physgun_freeze.vpcf"); freezeEffect.SetPosition(0, heldBody.Transform.PointToWorld(GrabbedPos)); } GrabEnd(); return; } MoveTargetDistance(Input.MouseWheel * TargetDistanceSpeed); bool rotating = Input.Down(InputButton.Use); bool snapping = false; if (rotating) { DoRotate(eyeRot, Input.MouseDelta * RotateSpeed); snapping = Input.Down(InputButton.Run); } GrabMove(eyePos, eyeDir, eyeRot, snapping); }
// Modified from Prop.cs to allow tweaking through code/cvar rather than having to go through model doc. private async Task Explode() { try { IsArmed = false; await Task.DelaySeconds(0.1f); Sound.FromWorld("rust_pumpshotgun.shootdouble", PhysicsBody.MassCenter); Particles.Create("particles/explosion_fireball.vpcf", PhysicsBody.MassCenter); Vector3 sourcePos = PhysicsBody.MassCenter; IEnumerable <Entity> overlaps = FindInSphere(sourcePos, BOMB_RADIUS); foreach (Entity overlap in overlaps) { if (overlap is not ModelEntity ent || !ent.IsValid() || ent.LifeState != LifeState.Alive || !ent.PhysicsBody.IsValid() || ent.IsWorld) { continue; } Vector3 targetPos = ent.PhysicsBody.MassCenter; float dist = Vector3.DistanceBetween(sourcePos, targetPos); if (dist > BOMB_RADIUS) { continue; } TraceResult tr = Trace.Ray(sourcePos, targetPos) .Ignore(this) .WorldOnly() .Run(); if (tr.Fraction < 1.0f) { continue; } float distanceMul = 1.0f - Math.Clamp(dist / BOMB_RADIUS, 0.0f, 1.0f); float damage = BOMB_DAMAGE * distanceMul; float force = BOMB_FORCE * distanceMul * ent.PhysicsBody.Mass; Vector3 forceDir = (targetPos - sourcePos).Normal; ent.TakeDamage(DamageInfo.Explosion(sourcePos, forceDir * force, damage) .WithAttacker(this)); } } catch (Exception e) { if (e.Message.Trim() == "A task was canceled.") { return; } Log.Error($"[TASK] {e.Message}: {e.StackTrace}"); } base.OnKilled(); }
public virtual void ShootEffects(int clipInfoIndex) { Host.AssertClient(); if (clipInfoIndex < 0 || clipInfoIndex >= ClipInfos.Length) { return; } ClipInfo clipInfo = ClipInfos[clipInfoIndex]; if (clipInfo == null) { return; } if (CarriableInfo.Category != CarriableCategories.Melee) { foreach (KeyValuePair <string, string> keyValuePair in clipInfo.ShootEffectList) { Particles.Create(keyValuePair.Key, EffectEntity, keyValuePair.Value); } } if (IsLocalPawn && clipInfo.ShakeEffect != null) { _ = new Perlin(clipInfo.ShakeEffect.Length, clipInfo.ShakeEffect.Speed, clipInfo.ShakeEffect.Size, clipInfo.ShakeEffect.Rotation); } ViewModelEntity?.SetAnimParameter("fire", true); CrosshairPanel?.CreateEvent("fire"); }
public override void OnNewModel(Model model) { if (Effect != null) { return; } Effect = Particles.Create("particles/green_circle_teleporter.vpcf", this, "Base", true); }
protected void CreateEffects() { if (effects != null) { return; } effects = Particles.Create("particles/physgun_end_nohit.vpcf"); }
protected virtual void ShootEffects() { Host.AssertClient(); PlaySound("rust_pistol.shoot"); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); ViewModelEntity?.SetAnimParam("fire", true); }
public void CreateHitEffects(Vector3 hitPos) { var particle = Particles.Create("particles/tool_hit.vpcf", hitPos); particle.SetPosition(0, hitPos); particle.Destroy(false); PlaySound("balloon_pop_cute"); }
protected override void ShootEffects() { Host.AssertClient(); PlaySound("rust_pumpshotgun.shoot"); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); Particles.Create("particles/pistol_ejectbrass.vpcf", EffectEntity, "ejection_point"); ViewModelEntity?.SetAnimParam("fire", true); }
protected virtual void UpdateEffects() { if (effects == null) { effects = Particles.Create("particles/physgun_end_nohit.vpcf"); //effects.SetEntity( 0, this, Vector3.Up * 20, true ); } effects.SetPos(0, WorldPos + WorldRot.Up * 20); }
protected async Task pulseIndicator() { await GameTask.Delay(100); while (!IsCollected) { using (Prediction.Off()) { Particles.Create(indicator, Position + Vector3.Up * 0.5f); } await GameTask.DelaySeconds(timeBetweenIndicators); } }
public override void OnCollected(TankPlayer player) { timeSinceCollected = 0; startClientMeter(To.Single(player.GetClientOwner())); // This RPC only works if inheriting from ModelEntity if (!string.IsNullOrEmpty(active)) { using (Prediction.Off()) { activeEffect = Particles.Create(active, player.Base, ""); } } base.OnCollected(player); }
private void TryUnfreezeAll(Player owner, Vector3 eyePos, Rotation eyeRot, Vector3 eyeDir) { var tr = Trace.Ray(eyePos, eyePos + eyeDir * MaxTargetDistance) .UseHitboxes() .Ignore(owner, false) .HitLayer(CollisionLayer.Debris) .Run(); if (!tr.Hit || !tr.Entity.IsValid() || tr.Entity.IsWorld) { return; } var rootEnt = tr.Entity.Root; if (!rootEnt.IsValid()) { return; } var physicsGroup = rootEnt.PhysicsGroup; if (physicsGroup == null) { return; } bool unfrozen = false; for (int i = 0; i < physicsGroup.BodyCount; ++i) { var body = physicsGroup.GetBody(i); if (!body.IsValid()) { continue; } if (body.BodyType == PhysicsBodyType.Static) { body.BodyType = PhysicsBodyType.Dynamic; unfrozen = true; } } if (unfrozen) { var freezeEffect = Particles.Create("particles/physgun_freeze.vpcf"); freezeEffect.SetPosition(0, tr.EndPosition); } }
protected virtual void ShootEffects() { Host.AssertClient(); PlaySound("rust_pistol.shoot"); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); if (Owner == Player.Local) { new Sandbox.ScreenShake.Perlin(); } ViewModelEntity?.SetAnimParam("fire", true); }
protected virtual void DoubleShootEffects() { Host.AssertClient(); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); ViewModelEntity?.SetAnimParam("fire_double", true); CrosshairPanel?.OnEvent("fire"); if (Owner == Player.Local) { new Sandbox.ScreenShake.Perlin(3.0f, 3.0f, 3.0f); } }
protected virtual void ShootEffects() { Host.AssertClient(); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); if (IsLocalPawn) { _ = new Sandbox.ScreenShake.Perlin(); } ViewModelEntity?.SetAnimParameter("fire", true); CrosshairPanel?.CreateEvent("fire"); }
protected virtual void DoubleShootEffects() { Host.AssertClient(); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); ViewModelEntity?.SetAnimBool("fire_double", true); CrosshairPanel?.CreateEvent("fire"); if (IsLocalPawn) { new Perlin(3.0f, 3.0f, 3.0f); } }
protected override void ShootEffects() { Host.AssertClient(); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); Particles.Create("particles/pistol_ejectbrass.vpcf", EffectEntity, "ejection_point"); if (Owner == Local.Pawn) { new Sandbox.ScreenShake.Perlin(0.5f, 4.0f, 1.0f, 0.5f); } ViewModelEntity?.SetAnimParameter("fire", true); CrosshairPanel?.CreateEvent("fire"); }
protected override void ShootEffects() { Host.AssertClient(); PlaySound("rust_smg.shoot"); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); Particles.Create("particles/pistol_ejectbrass.vpcf", EffectEntity, "ejection_point"); if (Owner == Player.Local) { new Sandbox.ScreenShake.Perlin(0.5f, 4.0f, 1.0f, 0.5f); } ViewModelEntity?.SetAnimParam("fire", true); }
protected virtual void ShootEffects() { Host.AssertClient(); Log.Info($"{EffectEntity} {ViewModelEntity} {IsFirstPersonMode} {CurrentView.Viewer} parent:{Parent}"); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); if (IsLocalPawn) { new Sandbox.ScreenShake.Perlin(); } ViewModelEntity?.SetAnimBool("fire", true); CrosshairPanel?.OnEvent("fire"); }
protected override void ShootEffects() { Host.AssertClient(); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); Particles.Create("particles/pistol_ejectbrass.vpcf", EffectEntity, "ejection_point"); ViewModelEntity?.SetAnimParam("fire", true); if (Owner == Player.Local) { _ = new Sandbox.ScreenShake.Perlin(1.0f, 1.5f, 2.0f); } CrosshairPanel?.OnEvent("fire"); }
private void tryCreateTreadMark(ref Vector3 lastParticlePos, Vector3 treadPos) { var difference = treadPos - lastParticlePos; if (lastParticlePos == default) // Snap to current position if we're still defaulted { difference = Vector3.Zero; lastParticlePos = treadPos; } if (difference.LengthSquared > treadLength * treadLength) // Spawn particle at perfect distance from last { lastParticlePos += difference.Normal * treadLength; var particle = Particles.Create("particles/tank_tread_mark.vpcf", lastParticlePos); particle.SetForward(0, Rotation.Forward); } }
protected override void ShootEffects() { Host.AssertClient(); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); Particles.Create("particles/pistol_ejectbrass.vpcf", EffectEntity, "ejection_point"); ViewModelEntity?.SetAnimBool("fire", true); if (IsLocalPawn) { new Perlin(1.0f, 1.5f, 2.0f); } CrosshairPanel?.CreateEvent("fire"); }
protected async Task startEmitting() { await GameTask.Delay(100); if (!ShouldEmitEffects) { return; } using (Prediction.Off()) { mainParticles = Particles.Create(main, Position + Vector3.Up * 32); fieldUpParticles = Particles.Create(field, Position); fieldUpParticles.SetForward(0, Vector3.Up); fieldDownParticles = Particles.Create(field, Position + Vector3.Up * 80); fieldDownParticles.SetForward(0, Vector3.Down); } }
//[ClientRpc] void BulletImpact(TraceResult tr) { // // No effects on resimulate // if (!Prediction.FirstTime) { return; } // // Drop a decal // var decalPath = Rand.FromArray(tr.Surface.ImpactEffects.BulletDecal); if (decalPath != null) { if (DecalDefinition.ByPath.TryGetValue(decalPath, out var decal)) { decal.PlaceUsingTrace(tr); } } // // Make an impact sound // if (!string.IsNullOrWhiteSpace(tr.Surface.Sounds.Bullet)) { Sound.FromWorld(tr.Surface.Sounds.Bullet, tr.EndPos); } // // Get us a particle effect // string particleName = Rand.FromArray(tr.Surface.ImpactEffects.Bullet); if (particleName == null) { particleName = Rand.FromArray(tr.Surface.ImpactEffects.Regular); } if (particleName != null) { var ps = Particles.Create(particleName, tr.EndPos); ps.SetForward(0, tr.Normal); } }
public override void Simulate() { if (!Host.IsServer) { return; } using (Prediction.Off()) { var input = Owner.Input; if (!input.Pressed(InputButton.Attack1)) { return; } var startPos = Owner.EyePos; var dir = Owner.EyeRot.Forward; var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance) .Ignore(Owner) .HitLayer(CollisionLayer.Debris) .Run(); if (!tr.Hit || !tr.Entity.IsValid()) { return; } if (tr.Entity is Player) { return; } CreateHitEffects(tr.EndPos); if (tr.Entity.IsWorld) { return; } tr.Entity.Delete(); var particle = Particles.Create("particles/physgun_freeze.vpcf"); particle.SetPos(0, tr.Entity.Position); } }
protected void ReflectBall(CollisionEventData eventData, float multiplier) { var reflect = Vector3.Reflect(eventData.PreVelocity.Normal, eventData.Normal.Normal).Normal; var normalDot = eventData.PreVelocity.Normal.Dot(eventData.Normal); // Don't do any reflection if we hit it at such an angle if (normalDot <= 0.10) { return; } // Collision sound happens at this point, not entity var sound = Sound.FromWorld(BounceSound.Name, eventData.Pos); sound.SetVolume(0.2f + Math.Clamp(eventData.Speed / 1250.0f, 0.0f, 0.8f)); sound.SetPitch(0.5f + Math.Clamp(eventData.Speed / 1250.0f, 0.0f, 0.5f)); var particle = Particles.Create("particles/ball_hit.vpcf", eventData.Pos); particle.SetPos(0, eventData.Pos); particle.Destroy(false); var newSpeed = Math.Max(eventData.PreVelocity.Length, eventData.Speed); newSpeed *= multiplier; // Adjust the speed depending on the hit normal, slight hit = more speed newSpeed *= (1 - normalDot / 2); var newVelocity = reflect * newSpeed; // TODO: not a fan of this, should determine by the dot normal newVelocity.z = 0; PhysicsBody.Velocity = newVelocity; PhysicsBody.AngularVelocity = Vector3.Zero; if (Debug) { DebugOverlay.Text(eventData.Pos, $"V {eventData.PreVelocity.Length} -> {newSpeed}", 5f); DebugOverlay.Text(eventData.Pos + Vector3.Up * 8, $"N. {normalDot}", 5f); DebugOverlay.Line(eventData.Pos, eventData.Pos - (eventData.PreVelocity.Normal * 64.0f), 5f); DebugOverlay.Line(eventData.Pos, eventData.Pos + (reflect * 64.0f), 5f); } }
public virtual void ShootEffects() { Host.AssertClient(); var muzzle = EffectEntity.GetAttachment("muzzle"); bool InWater = Physics.TestPointContents(muzzle.Pos, CollisionLayer.Water); Sound.FromEntity("rust_pistol.shoot", this); Particles.Create("particles/pistol_muzzleflash.vpcf", EffectEntity, "muzzle"); ViewModelEntity?.SetAnimParam("fire", true); CrosshairPanel?.OnEvent("onattack"); if (Owner == Player.Local) { new Sandbox.ScreenShake.Perlin(0.5f, 2.0f, 0.5f); } }