Exemple #1
0
        public void TickEntityPhysics(EntityPos pos, EntityControls controls, float dt)
        {
            IBlockAccessor blockAccessor = entity.World.BlockAccessor;

            foreach (EntityLocomotion locomotor in Locomotors)
            {
                if (locomotor.Applicable(entity, pos, controls))
                {
                    locomotor.Apply(dt, entity, pos, controls);
                }
            }

            EntityAgent agent = entity as EntityAgent;

            if (agent?.MountedOn != null)
            {
                pos.SetFrom(agent.MountedOn.MountPosition);
                pos.Motion.X = 0;
                pos.Motion.Y = 0;
                pos.Motion.Z = 0;
                return;
            }


            pos.Motion.X = GameMath.Clamp(pos.Motion.X, -10, 10);
            pos.Motion.Y = GameMath.Clamp(pos.Motion.Y, -10, 10);
            pos.Motion.Z = GameMath.Clamp(pos.Motion.Z, -10, 10);

            if (!controls.NoClip)
            {
                DisplaceWithBlockCollision(pos, controls, dt);
            }
            else
            {
                pos.X += pos.Motion.X;
                pos.Y += pos.Motion.Y;
                pos.Z += pos.Motion.Z;

                entity.Swimming     = false;
                entity.FeetInLiquid = false;
                entity.OnGround     = false;
            }



            // Shake the player violently when falling at high speeds

            /*if (movedy < -50)
             * {
             *  pos.X += (rand.NextDouble() - 0.5) / 5 * (-movedy / 50f);
             *  pos.Z += (rand.NextDouble() - 0.5) / 5 * (-movedy / 50f);
             * }
             */

            //return result;
        }
Exemple #2
0
        public void TickEntityPhysics(EntityPos pos, EntityControls controls, float dt)
        {
            float dtFac = 60 * dt;

            // This seems to make creatures clip into the terrain. Le sigh.
            // Since we currently only really need it for when the creature is dead, let's just use it only there

            // Also running animations for all nearby living entities is pretty CPU intensive so
            // the AnimationManager also just ticks if the entity is in view or dead
            if (!entity.Alive)
            {
                AdjustCollisionBoxToAnimation(dtFac);
            }


            foreach (EntityLocomotion locomotor in Locomotors)
            {
                if (locomotor.Applicable(entity, pos, controls))
                {
                    locomotor.Apply(dt, entity, pos, controls);
                }
            }

            EntityAgent agent = entity as EntityAgent;

            if (agent?.MountedOn != null)
            {
                pos.SetFrom(agent.MountedOn.MountPosition);
                pos.Motion.X = 0;
                pos.Motion.Y = 0;
                pos.Motion.Z = 0;
                return;
            }

            pos.Motion.X = GameMath.Clamp(pos.Motion.X, -10, 10);
            pos.Motion.Y = GameMath.Clamp(pos.Motion.Y, -10, 10);
            pos.Motion.Z = GameMath.Clamp(pos.Motion.Z, -10, 10);

            if (!controls.NoClip)
            {
                DisplaceWithBlockCollision(pos, controls, dt);
            }
            else
            {
                pos.X += pos.Motion.X * dt * 60f;
                pos.Y += pos.Motion.Y * dt * 60f;
                pos.Z += pos.Motion.Z * dt * 60f;

                entity.Swimming     = false;
                entity.FeetInLiquid = false;
                entity.OnGround     = false;
            }



            // Shake the player violently when falling at high speeds

            /*if (movedy < -50)
             * {
             *  pos.X += (rand.NextDouble() - 0.5) / 5 * (-movedy / 50f);
             *  pos.Z += (rand.NextDouble() - 0.5) / 5 * (-movedy / 50f);
             * }
             */

            //return result;
        }
Exemple #3
0
        public void TickEntityPhysics(EntityPos pos, EntityControls controls, float dt)
        {
            FrameProfilerUtil profiler = entity.World.FrameProfiler;

            profiler.Mark("init");
            float dtFac = 60 * dt;

            // This seems to make creatures clip into the terrain. Le sigh.
            // Since we currently only really need it for when the creature is dead, let's just use it only there

            // Also running animations for all nearby living entities is pretty CPU intensive so
            // the AnimationManager also just ticks if the entity is in view or dead
            if (!entity.Alive)
            {
                AdjustCollisionBoxToAnimation(dtFac);
            }


            if (controls.TriesToMove && entity.OnGround && !entity.Swimming)
            {
                pos.Motion.Add(windForce);
            }


            foreach (EntityLocomotion locomotor in Locomotors)
            {
                if (locomotor.Applicable(entity, pos, controls))
                {
                    locomotor.Apply(dt, entity, pos, controls);
                }
            }

            profiler.Mark("locomotors");

            int knockbackState = entity.Attributes.GetInt("dmgkb");

            if (knockbackState > 0)
            {
                float acc = entity.Attributes.GetFloat("dmgkbAccum") + dt;
                entity.Attributes.SetFloat("dmgkbAccum", acc);

                if (knockbackState == 1)
                {
                    float str = 1 * 30 * dt * (entity.OnGround ? 1 : 0.5f);
                    pos.Motion.X += entity.WatchedAttributes.GetDouble("kbdirX") * str;
                    pos.Motion.Y += entity.WatchedAttributes.GetDouble("kbdirY") * str;
                    pos.Motion.Z += entity.WatchedAttributes.GetDouble("kbdirZ") * str;
                    entity.Attributes.SetInt("dmgkb", 2);
                }

                if (acc > 2 / 30f)
                {
                    entity.Attributes.SetInt("dmgkb", 0);
                    entity.Attributes.SetFloat("dmgkbAccum", 0);
                    float str = 0.5f * 30 * dt;
                    pos.Motion.X -= entity.WatchedAttributes.GetDouble("kbdirX") * str;
                    pos.Motion.Y -= entity.WatchedAttributes.GetDouble("kbdirY") * str;
                    pos.Motion.Z -= entity.WatchedAttributes.GetDouble("kbdirZ") * str;
                }
            }

            EntityAgent agent = entity as EntityAgent;

            if (agent?.MountedOn != null)
            {
                pos.SetFrom(agent.MountedOn.MountPosition);
                pos.Motion.X = 0;
                pos.Motion.Y = 0;
                pos.Motion.Z = 0;
                return;
            }

            profiler.Mark("knockback-and-mountedcheck");
            profiler.Enter("collision");

            if (pos.Motion.LengthSq() > 100D)
            {
                pos.Motion.X = GameMath.Clamp(pos.Motion.X, -10, 10);
                pos.Motion.Y = GameMath.Clamp(pos.Motion.Y, -10, 10);
                pos.Motion.Z = GameMath.Clamp(pos.Motion.Z, -10, 10);
            }

            if (!controls.NoClip)
            {
                DisplaceWithBlockCollision(pos, controls, dt);
            }
            else
            {
                pos.X += pos.Motion.X * dt * 60f;
                pos.Y += pos.Motion.Y * dt * 60f;
                pos.Z += pos.Motion.Z * dt * 60f;

                entity.Swimming     = false;
                entity.FeetInLiquid = false;
                entity.OnGround     = false;
            }


            profiler.Leave();


            // Shake the player violently when falling at high speeds

            /*if (movedy < -50)
             * {
             *  pos.X += (rand.NextDouble() - 0.5) / 5 * (-movedy / 50f);
             *  pos.Z += (rand.NextDouble() - 0.5) / 5 * (-movedy / 50f);
             * }
             */

            //return result;
        }