Example #1
0
        public void DoStaticBlowerRegion(MaskData blowerRegion, int deltaX, int deltaZ, int startY, int endY)
        {
            for (int i = 0; i < moverCount; i++)
            {
                if (moverWeDoNotMove[i])
                {
                    continue;
                }

                int moverStartX = moverInitialPositions[i].X + moverCharacterPhysics[i].startX;
                int moverEndX   = moverInitialPositions[i].X + moverCharacterPhysics[i].endX;

                int moverStartY = moverInitialPositions[i].Y;
                int moverEndY   = moverStartY + moverCharacterPhysics[i].height;
                int moverZ      = moverInitialPositions[i].Z;

                if (blowerRegion.IsSetInXRange(moverStartX, moverEndX, moverZ))
                {
                    int  groundHeight = GetGroundHeightInXRange(moverStartX, moverEndX, moverZ, moverStartY, moverEndY, moverActors[i], staticOnly: true);
                    bool onGround     = (groundHeight == moverStartY);

                    if (!(moverEndY < startY || moverStartY >= endY)) // <- in the blower's Y range
                    {
                        CharacterPhysics.TryMoveHorizontalDidHitWall(ref moverCharacterPhysics[i], this, deltaX, deltaZ, onGround, ref moverActors[i].position, staticOnly: true);
                    }
                }
            }
        }
Example #2
0
        public void DoStaticGroundConveyorRegion(MaskData conveyorRegion, int deltaX, int deltaZ)
        {
            for (int i = 0; i < moverCount; i++)
            {
                if (moverWeDoNotMove[i])
                {
                    continue;
                }

                int moverStartX = moverInitialPositions[i].X + moverCharacterPhysics[i].startX;
                int moverEndX   = moverInitialPositions[i].X + moverCharacterPhysics[i].endX;

                int moverY = moverInitialPositions[i].Y;
                int moverZ = moverInitialPositions[i].Z;

                if (conveyorRegion.IsSetInXRange(moverStartX, moverEndX, moverZ))
                {
                    int groundHeight = GetGroundHeightInXRange(moverStartX, moverEndX, moverZ, moverY, moverY + moverCharacterPhysics[i].height, moverActors[i], staticOnly: true);

                    if (moverY == groundHeight) // <- on the ground
                    {
                        CharacterPhysics.TryMoveHorizontalDidHitWall(ref moverCharacterPhysics[i], this, deltaX, deltaZ, true, ref moverActors[i].position, staticOnly: true);
                    }
                }
            }
        }
Example #3
0
        public static MotionResult PhysicsStepHorizontal(ref CharacterPhysicsInfo cpi,
                                                         ref Position position, ref ThreeDVelocity velocity,
                                                         bool onGround,
                                                         int coefficientOfRestitution256,
                                                         int groundFriction256,
                                                         WorldPhysics physics)
        {
            MotionResult result = MotionResult.None;

            int newPositionX = velocity.X.Update(position.X);
            int newPositionZ = velocity.Z.Update(position.Z);
            int deltaX       = newPositionX - position.X;
            int deltaZ       = newPositionZ - position.Z;

            if (deltaX != 0)
            {
                if (CharacterPhysics.TryMoveHorizontalDidHitWall(ref cpi, physics, deltaX, 0, onGround, ref position))
                {
                    // Hit wall, bounce:
                    velocity.X.Scale256(-coefficientOfRestitution256);
                    result = MotionResult.HitWall;
                }
            }

            // Z-motion just stops if it hits anything
            if (deltaZ != 0 && CharacterPhysics.TryMoveHorizontalDidHitWall(ref cpi, physics, 0, deltaZ, onGround, ref position))
            {
                velocity.Z.Reset();
                // NOTE: Currently not even bothering to give a hit result, just carry on...
            }

            // TODO: Slope handling for rolling objects

            if (onGround)
            {
                // Friction:
                velocity.X.Scale256(groundFriction256);
                velocity.Z.Scale256(groundFriction256);
            }

            return(result);
        }