public override void Tick() { if (TheRegion.Delta <= 0) { return; } if (!IsSpawned) { return; } PathUpdate -= TheRegion.Delta; if (PathUpdate <= 0) { UpdatePath(); } if (Path != null) { PathMovement = true; Location spos = GetPosition(); while (Path.Length > 0 && ((Path.Peek() - spos).LengthSquared() < PathFindCloseEnough || (Path.Peek() - spos + new Location(0, 0, -1.5)).LengthSquared() < PathFindCloseEnough)) { Path.Pop(); } if (Path.Length <= 0) { Path = null; } else { Location targetdir = (Path.Peek() - spos).Normalize(); Location movegoal = Utilities.RotateVector(targetdir, (270 + Direction.Yaw) * Utilities.PI180); Vector2 movegoal2 = new Vector2((double)movegoal.X, (double)movegoal.Y); if (movegoal2.LengthSquared() > 0) { movegoal2.Normalize(); } XMove = movegoal2.X; YMove = movegoal2.Y; if (movegoal.Z > 0.4) { CBody.Jump(); } } } if (Path == null && PathMovement) { XMove = 0; YMove = 0; PathMovement = false; } while (Direction.Yaw < 0) { Direction.Yaw += 360; } while (Direction.Yaw > 360) { Direction.Yaw -= 360; } if (Direction.Pitch > 89.9f) { Direction.Pitch = 89.9f; } if (Direction.Pitch < -89.9f) { Direction.Pitch = -89.9f; } CBody.ViewDirection = Utilities.ForwardVector_Deg(Direction.Yaw, Direction.Pitch).ToBVector(); if (Upward && !IsFlying && !pup && CBody.SupportFinder.HasSupport) { CBody.Jump(); pup = true; } else if (!Upward) { pup = false; } double speedmod = new Vector2(XMove, YMove).Length() * 1.25; speedmod *= (1f + SprintOrWalk * 0.5f); if (ItemDoSpeedMod) { speedmod *= ItemSpeedMod; } Material mat = TheRegion.GetBlockMaterial(GetPosition() + new Location(0, 0, -0.05f)); speedmod *= mat.GetSpeedMod(); CBody.StandingSpeed = CBStandSpeed * speedmod; CBody.CrouchingSpeed = CBCrouchSpeed * speedmod; double frictionmod = 1f; frictionmod *= mat.GetFrictionMod(); CBody.SlidingForce = CBSlideForce * frictionmod * Mass; CBody.AirForce = CBAirForce * frictionmod * Mass; CBody.TractionForce = CBTractionForce * frictionmod * Mass; CBody.VerticalMotionConstraint.MaximumGlueForce = CBGlueForce * Mass; if (CurrentSeat == null) { Vector3 movement = new Vector3(XMove, YMove, 0); if (Upward && IsFlying) { movement.Z = 1; } else if (Downward && IsFlying) { movement.Z = -1; } if (movement.LengthSquared() > 0) { movement.Normalize(); } if (Downward) { CBody.StanceManager.DesiredStance = Stance.Crouching; } else { CBody.StanceManager.DesiredStance = DesiredStance; } CBody.HorizontalMotionConstraint.MovementDirection = new Vector2(movement.X, movement.Y); Location pos = GetPosition(); Location rad = new Location(CBody.BodyRadius, CBody.BodyRadius, 0); double halfeye = CBHHeight * (CBody.StanceManager.CurrentStance == Stance.Standing ? 1.8 : 1.5) * 0.5; bool uw1 = TheRegion.InWater(pos - rad, pos + rad + new Location(0, 0, halfeye)); bool uw2 = TheRegion.InWater(pos - rad + new Location(0, 0, halfeye), pos + rad + new Location(0, 0, halfeye * 2)); if (uw1 || uw2) { double mult = uw1 ? (uw2 ? 0.6 : 0.3) : 0.3; SetForSwim(mult, Body.Space.ForceUpdater.Gravity * (1.0 - mult)); } else { SetForGround(); } if (IsFlying) { Location forw = Utilities.RotateVector(new Location(-movement.Y, movement.X, movement.Z), Direction.Yaw * Utilities.PI180, Direction.Pitch * Utilities.PI180); SetPosition(GetPosition() + forw * TheRegion.Delta * CBStandSpeed * 2 * speedmod); CBody.HorizontalMotionConstraint.MovementDirection = Vector2.Zero; Body.LinearVelocity = new Vector3(0, 0, 0); } else if (IsSwimlogic) { Location forw = Utilities.RotateVector(new Location(movement.X, movement.Y, 0), Direction.Yaw * Utilities.PI180, Direction.Pitch * Utilities.PI180); if (Upward) { forw.Z = 1; } else if (Downward) { forw.Z = -1; } SwimForce(forw.ToBVector()); } } else { CurrentSeat.HandleInput(this); } base.Tick(); RigidTransform transf = new RigidTransform(Vector3.Zero, Body.Orientation); Body.CollisionInformation.Shape.GetBoundingBox(ref transf, out BoundingBox box); MinZ = box.Min.Z; }
public void UpdateForPacketFromServer(double gtt, long ID, Location pos, Location vel, bool _pup) { ServerLocation = pos; if (ServerFlags.HasFlag(YourStatusFlags.INSECURE_MOVEMENT)) { return; } if (InVehicle) { return; } // TODO: big solid entities! double now = TheRegion.GlobalTickTimeLocal; if (TheClient.CVars.n_movemode.ValueI == 2) { // TODO: Remove outsider chunks! for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { for (int z = -1; z <= 1; z++) { Vector3i ch = TheRegion.ChunkLocFor(pos) + new Vector3i(x, y, z); Chunk chunk = TheRegion.GetChunk(ch); if (chunk == null) { continue; } if (!NMTWOMeshes.ContainsKey(ch)) { if (chunk.FCO != null) { FullChunkObject im = new FullChunkObject(chunk.FCO.Position, chunk.FCO.ChunkShape); NMTWOWorld.Add(im); NMTWOMeshes[ch] = im; } } } } } AddUIS(); int xf = 0; double jumpback = gtt - lGTT; if (jumpback < 0) { return; } double target = TheRegion.GlobalTickTimeLocal - jumpback; UserInputSet past = null; while (xf < Input.Length) { UserInputSet uis = Input[xf]; if (uis.GlobalTimeLocal < target) { past = uis; Input.Pop(); continue; } else if (xf == 0) { double mult = Math.Max(Math.Min(jumpback / TheClient.CVars.n_movement_adjustment.ValueD, 1.0), 0.01); NMTWOSetPosition(uis.Position + (pos - uis.Position) * mult); NMTWOSetVelocity(uis.Velocity + (vel - uis.Velocity) * mult); } xf++; double delta; if (xf < 2) { if (past == null) { continue; } delta = uis.GlobalTimeLocal - target; SetBodyMovement(NMTWOCBody, past); } else { UserInputSet prev = Input[xf - 2]; delta = uis.GlobalTimeLocal - prev.GlobalTimeLocal; SetBodyMovement(NMTWOCBody, prev); } SetMoveSpeed(NMTWOCBody, uis); if (!_pup) { NMTWOTryToJump(uis); } lPT = uis.GlobalTimeLocal; NMTWOWorld.Update((float)delta); FlyForth(NMTWOCBody, uis, delta); // TODO: Entirely disregard NWTWOWorld if flying? } AddUIS(); SetPosition(NMTWOGetPosition()); SetVelocity(new Location(NMTWOCBody.Body.LinearVelocity)); pup = _pup; lGTT = gtt; } else { double delta = lPT - now; Location dir = pos - TheClient.Player.GetPosition(); if (dir.LengthSquared() < TheClient.CVars.n_movement_maxdistance.ValueF * TheClient.CVars.n_movement_maxdistance.ValueF) { SetPosition(GetPosition() + dir / Math.Max(TheClient.CVars.n_movement_adjustment.ValueF / delta, 1)); Location veldir = vel - GetVelocity(); SetVelocity(GetVelocity() + veldir / Math.Max(TheClient.CVars.n_movement_adjustment.ValueF / delta, 1)); } else { TheClient.Player.SetPosition(pos); TheClient.Player.SetVelocity(vel); } lPT = now; } }