Пример #1
0
    public override void _PhysicsProcess(float Delta)
    {
        Mesh.SetRotationDegrees(new Vector3(0, Mesh.RotationDegrees.y + (360 * Delta * RPS), 0));
        Life += Delta;

        if (PhysicsEnabled)
        {
            Momentum = MoveAndSlide(Momentum, new Vector3(0, 1, 0), floorMaxAngle: 50);
            if (!CurrentChunkTuple.Equals(World.GetChunkTuple(Translation)))            //We just crossed into a different chunk
            {
                World.Chunks[CurrentChunkTuple].Items.Remove(this);
                CurrentChunkTuple = World.GetChunkTuple(Translation);
                World.AddItemToChunk(this);
                Net.SteelRpc(World.Self, nameof(World.DropOrUpdateItem), Type, Translation, Momentum, GetName());
            }

            if (IsOnFloor())
            {
                //Doing friction
                Vector3 Horz = new Vector3(Momentum.x, 0, Momentum.z);
                Horz       = Horz.Normalized() * Mathf.Clamp(Horz.Length() - (Friction * Delta), 0, Mathf.Abs(MaxFallSpeed));
                Momentum.x = Horz.x;
                Momentum.z = Horz.z;

                if (Horz.Length() <= 0)
                {
                    PhysicsEnabled = false;
                }
            }

            if (PhysicsEnabled)
            {
                Momentum.y -= Gravity * Delta;
                if (Momentum.y < MaxFallSpeed)
                {
                    Momentum.y = MaxFallSpeed;
                }
            }
            else
            {
                Momentum = new Vector3(0, 0, 0);
                World.Grid.AddItem(this);
            }
        }
    }
Пример #2
0
    public override void _Process(float Delta)     //NOTE: Only runs on server
    {
        Assert.ActualAssert(Net.Work.IsNetworkServer());

        TimeSinceUpdate += Delta;

        if (!DepreciatedCurrentChunkTuple.Equals(World.GetChunkTuple(Translation)))
        {
            World.Chunks[DepreciatedCurrentChunkTuple].Mobs.Remove(this);
            World.AddMobToChunk(this);
        }

        if (CurrentArea != GridClass.CalculateArea(Translation))
        {
            CurrentArea = GridClass.CalculateArea(Translation);
            World.Grid.QueueRemoveItem(this);
            World.Grid.AddItem(this);
        }

        UpdateFloor();
        CalcWants(Floor);

        if (OnFloor)
        {
            TargetPoint.Match(
                some: Target => {
                if (Target.Pos.Flattened().DistanceTo(Translation.Flattened()) <= 2)
                {
                    TargetPoint = PointData.None();
                }
                else
                {
                    //Apply push toward TargetPoint but don't go to fast
                    Momentum += ClampVec3(
                        Target.Pos.Flattened() - Translation.Flattened(),
                        Acceleration * Delta + Friction * Delta,
                        Acceleration * Delta + Friction * Delta
                        );
                    Vector3 Clamped = ClampVec3(Momentum.Flattened(), 0, TopSpeed);
                    Momentum.x      = Clamped.x;
                    Momentum.z      = Clamped.z;
                }
            },

                none: () => { }
                );

            //Friction
            Vector3 Horz = Momentum.Flattened();
            Horz       = Horz.Normalized() * Clamp(Horz.Length() - Friction * Delta, 0, TopSpeed);
            Momentum.x = Horz.x;
            Momentum.z = Horz.z;
        }
        else                                                                               //Not on floor
        {
            Momentum.y = Clamp(Momentum.y - Gravity * Delta, -MaxFallSpeed, MaxFallSpeed); //Apply gravity
        }
        var OriginalChunkTuple = World.GetChunkTuple(Translation);

        Momentum = Move(Momentum, Delta, 1, 60, TopSpeed);

        Entities.MovedTick(this, OriginalChunkTuple);

        Entities.AsServerMaybePhaseOut(this);
        Entities.SendUpdate(Name, Translation);
    }
Пример #3
0
    public override void _Process(float Delta)     //NOTE: Only runs on server
    {
        TimeSinceUpdate += Delta;

        if (!CurrentChunkTuple.Equals(World.GetChunkTuple(Translation)))
        {
            World.Chunks[CurrentChunkTuple].Mobs.Remove(this);
            World.AddMobToChunk(this);
        }

        if (CurrentArea != GridClass.CalculateArea(Translation))
        {
            CurrentArea = GridClass.CalculateArea(Translation);
            World.Grid.QueueRemoveItem(this);
            World.Grid.AddItem(this);

            UpdateFloor();
        }

        CalcWants(Floor);

        if (OnFloor)
        {
            TargetPoint.Match(
                some: Target =>
            {
                if (Target.Pos.Flattened().DistanceTo(Translation.Flattened()) <= 2)
                {
                    TargetPoint = PointData.None();
                }
                else
                {
                    //Apply push toward TargetPoint but don't go to fast
                    Momentum += ClampVec3(
                        Target.Pos.Flattened() - Translation.Flattened(),
                        Acceleration * Delta + Friction * Delta,
                        Acceleration * Delta + Friction * Delta
                        );
                    Vector3 Clamped = ClampVec3(Momentum.Flattened(), 0, TopSpeed);
                    Momentum.x      = Clamped.x;
                    Momentum.z      = Clamped.z;
                }
            },

                none: () => {}
                );

            //Friction
            Vector3 Horz = Momentum.Flattened();
            Horz       = Horz.Normalized() * Clamp(Horz.Length() - Friction * Delta, 0, TopSpeed);
            Momentum.x = Horz.x;
            Momentum.z = Horz.z;
        }
        else                                                                               //Not on floor
        {
            Momentum.y = Clamp(Momentum.y - Gravity * Delta, -MaxFallSpeed, MaxFallSpeed); //Apply gravity
        }
        Momentum = Move(Momentum, Delta, 2, 60, TopSpeed);
        if (TimeSinceUpdate >= MaxTimeSinceUpdate)
        {
            TimeSinceUpdate = 0;

            foreach (int Id in Net.PeerList)
            {
                if (Id == Net.Work.GetNetworkUniqueId())
                {
                    continue;
                }

                var ChunkTuple = World.GetChunkTuple(Translation);
                if (World.RemoteLoadedChunks[Id].Contains(ChunkTuple))
                {
                    //This player has our chunk loaded, update
                    RpcId(Id, nameof(Update), Translation);
                }
            }
        }
    }