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); }
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); }
public override void BuildInput(InputBuilder owner) { if (!GrabbedEntity.IsValid()) { return; } if (!owner.Down(InputButton.Attack1)) { return; } if (owner.Down(InputButton.Use)) { owner.ViewAngles = owner.OriginalViewAngles; } }
public void BuildInput(ClientInput owner) { if (!GrabbedEntity.IsValid()) { return; } if (!owner.Down(InputButton.Attack1)) { return; } if (owner.Down(InputButton.Use)) { owner.ViewAngles = owner.LastViewAngles; } }
private void GrabEnd() { if (holdJoint.IsValid()) { holdJoint.Remove(); } if (heldBody.IsValid()) { heldBody.EnableAutoSleeping = true; } if (Owner.IsValid() && GrabbedEntity.IsValid()) { Owner.Pvs.Remove(GrabbedEntity); } heldBody = null; GrabbedEntity = null; grabbing = false; }
private void GrabEnd() { if (holdJoint.IsValid()) { holdJoint.Remove(); } if (heldBody.IsValid()) { heldBody.EnableAutoSleeping = true; } var client = GetClientOwner(); if (client != null && GrabbedEntity.IsValid()) { client.Pvs.Remove(GrabbedEntity); } heldBody = null; GrabbedEntity = null; grabbing = false; }
protected virtual void UpdateEffects() { var owner = Owner; if (owner == null || !BeamActive || !IsActiveChild()) { KillEffects(); return; } var startPos = owner.EyePos; var dir = owner.EyeRot.Forward; var tr = Trace.Ray(startPos, startPos + dir * MaxTargetDistance) .UseHitboxes() .Ignore(owner) .Run(); if (Beam == null) { Beam = Particles.Create("particles/physgun_beam.vpcf", tr.EndPos); } Beam.SetEntityAttachment(0, EffectEntity, "muzzle", true); if (GrabbedEntity.IsValid() && !GrabbedEntity.IsWorld) { var physGroup = GrabbedEntity.PhysicsGroup; if (physGroup != null && GrabbedBone >= 0) { var physBody = physGroup.GetBody(GrabbedBone); if (physBody != null) { Beam.SetPos(1, physBody.Transform.PointToWorld(GrabbedPos)); } } else { Beam.SetEntity(1, GrabbedEntity, GrabbedPos, true); } lastBeamPos = GrabbedEntity.WorldPos + GrabbedEntity.WorldRot * GrabbedPos; EndNoHit?.Destory(false); EndNoHit = null; if (GrabbedEntity is ModelEntity modelEnt) { lastGrabbedEntity = modelEnt; modelEnt.GlowState = GlowStates.GlowStateOn; modelEnt.GlowDistanceStart = 0; modelEnt.GlowDistanceEnd = 1000; modelEnt.GlowColor = new Color(0.1f, 1.0f, 1.0f, 1.0f); modelEnt.GlowActive = true; foreach (var child in lastGrabbedEntity.Children.OfType <ModelEntity>()) { child.GlowState = GlowStates.GlowStateOn; child.GlowDistanceStart = 0; child.GlowDistanceEnd = 1000; child.GlowColor = new Color(0.1f, 1.0f, 1.0f, 1.0f); child.GlowActive = true; } } } else { lastBeamPos = tr.EndPos; // Vector3.Lerp( lastBeamPos, tr.EndPos, Time.Delta * 10 ); Beam.SetPos(1, lastBeamPos); if (EndNoHit == null) { EndNoHit = Particles.Create("particles/physgun_end_nohit.vpcf", lastBeamPos); } EndNoHit.SetPos(0, lastBeamPos); } }
public override void Simulate(Client client) { if (Owner is not Player owner) { return; } var eyePos = owner.EyePosition; var eyeDir = owner.EyeRotation.Forward; var eyeRot = Rotation.From(new Angles(0.0f, owner.EyeRotation.Angles().yaw, 0.0f)); if (Input.Pressed(InputButton.Attack1)) { (Owner as AnimEntity)?.SetAnimParameter("b_attack", true); if (!grabbing) { grabbing = true; } } bool grabEnabled = grabbing && Input.Down(InputButton.Attack1); bool wantsToFreeze = Input.Pressed(InputButton.Attack2); if (GrabbedEntity.IsValid() && wantsToFreeze) { (Owner as AnimEntity)?.SetAnimParameter("b_attack", true); } BeamActive = grabEnabled; if (IsServer) { using (Prediction.Off()) { if (!holdBody.IsValid()) { return; } if (grabEnabled) { if (heldBody.IsValid()) { UpdateGrab(eyePos, eyeRot, eyeDir, wantsToFreeze); } else { TryStartGrab(owner, eyePos, eyeRot, eyeDir); } } else if (grabbing) { GrabEnd(); } if (!grabbing && Input.Pressed(InputButton.Reload)) { TryUnfreezeAll(owner, eyePos, eyeRot, eyeDir); } } } if (BeamActive) { Input.MouseWheel = 0; } }
protected virtual void UpdateEffects() { var owner = Owner as Player; if (owner == null || !BeamActive || owner.ActiveChild != this) { KillEffects(); return; } var startPos = owner.EyePosition; var dir = owner.EyeRotation.Forward; var tr = Trace.Ray(startPos, startPos + dir * MaxTargetDistance) .UseHitboxes() .Ignore(owner, false) .HitLayer(CollisionLayer.Debris) .Run(); if (Beam == null) { Beam = Particles.Create("particles/physgun_beam.vpcf", tr.EndPosition); } Beam.SetEntityAttachment(0, EffectEntity, "muzzle", true); if (GrabbedEntity.IsValid() && !GrabbedEntity.IsWorld) { var physGroup = GrabbedEntity.PhysicsGroup; if (physGroup != null && GrabbedBone >= 0) { var physBody = physGroup.GetBody(GrabbedBone); if (physBody != null) { Beam.SetPosition(1, physBody.Transform.PointToWorld(GrabbedPos)); } } else { Beam.SetEntity(1, GrabbedEntity, GrabbedPos, true); } lastBeamPos = GrabbedEntity.Position + GrabbedEntity.Rotation * GrabbedPos; EndNoHit?.Destroy(false); EndNoHit = null; if (GrabbedEntity is ModelEntity modelEnt) { lastGrabbedEntity = modelEnt; var glow = modelEnt.Components.GetOrCreate <Glow>(); glow.Active = true; glow.RangeMin = 0; glow.RangeMax = 1000; glow.Color = new Color(0.1f, 1.0f, 1.0f, 1.0f); foreach (var child in lastGrabbedEntity.Children.OfType <ModelEntity>()) { if (child is Player) { continue; } glow = child.Components.GetOrCreate <Glow>(); glow.Active = true; glow.RangeMin = 0; glow.RangeMax = 1000; glow.Color = new Color(0.1f, 1.0f, 1.0f, 1.0f); } } } else { lastBeamPos = tr.EndPosition; // Vector3.Lerp( lastBeamPos, tr.EndPosition, Time.Delta * 10 ); Beam.SetPosition(1, lastBeamPos); if (EndNoHit == null) { EndNoHit = Particles.Create("particles/physgun_end_nohit.vpcf", lastBeamPos); } EndNoHit.SetPosition(0, lastBeamPos); } }