public override void Tick() { base.Tick(); 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(); } }
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; }