示例#1
0
        void UpdateAnimationTree()
        {
            if (EntitySystemWorld.Instance.Simulation && !EntitySystemWorld.Instance.SystemPauseOfSimulation)
            {
                AnimationTree tree = GetFirstAnimationTree();
                if (tree != null)
                {
                    bool onGround = GetElapsedTimeSinceLastGroundContact() < .2f;                    //IsOnGround();

                    bool   move      = false;
                    Degree moveAngle = 0;
                    float  moveSpeed = 0;
                    if (onGround && GroundRelativeVelocitySmooth.ToVec2().Length() > .05f)
                    {
                        move = true;
                        Vec2   localVec = (Rotation.GetInverse() * GroundRelativeVelocity).ToVec2();
                        Radian angle    = MathFunctions.ATan(localVec.Y, localVec.X);
                        moveAngle = angle.InDegrees();
                        moveSpeed = GroundRelativeVelocity.ToVec2().Length();
                    }

                    tree.SetParameterValue("move", move ? 1 : 0);
                    tree.SetParameterValue("run", move && IsNeedRun() ? 1 : 0);
                    tree.SetParameterValue("moveAngle", moveAngle);
                    tree.SetParameterValue("moveSpeed", moveSpeed);
                    tree.SetParameterValue("fly", !onGround ? 1 : 0);
                }
            }
        }
示例#2
0
        void MomentaryTurnToPositionUpdate(Vec3 turnToPosition)
        {
            if (turretBody == null || baseBody == null || mainGunAttachedObject == null)
            {
                return;
            }

            Vec3 diff = turnToPosition - Position;

            Radian horizontalAngle = MathFunctions.ATan(diff.Y, diff.X);
            Radian verticalAngle   = MathFunctions.ATan(diff.Z, diff.ToVec2().Length());

            turretBody.Rotation = new Angles(0, 0, -horizontalAngle.InDegrees()).ToQuat();

            Quat rot = baseBody.Rotation.GetInverse() * turretBody.Rotation;

            Quat verticalRot = new Angles(0, verticalAngle.InDegrees(), 0).ToQuat();

            mainGunAttachedObject.PositionOffset = rot * mainGunOffsetPosition;
            mainGunAttachedObject.RotationOffset = rot * verticalRot;
            RecalculateMapBounds();

            if (EntitySystemWorld.Instance.IsServer())
            {
                server_shouldSendTurnToPosition = turnToPosition;
            }
        }
        void UpdateAnimationTree()
        {
            if (EntitySystemWorld.Instance.Simulation && !EntitySystemWorld.Instance.SystemPauseOfSimulation)
            {
                AnimationTree tree = GetFirstAnimationTree();
                if (tree != null)
                {
                    tree.SetParameterValue("weapon", activeWeapon != null ? 1 : 0);

                    Radian horizontalAngle = 0;
                    Radian verticalAngle   = 0;

                    PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                    if (playerIntellect != null)
                    {
                        Vec2 vec = Vec2.Zero;
                        vec.X += playerIntellect.GetControlKeyStrength(GameControlKeys.Forward);
                        vec.X -= playerIntellect.GetControlKeyStrength(GameControlKeys.Backward);
                        vec.Y += playerIntellect.GetControlKeyStrength(GameControlKeys.Left);
                        vec.Y -= playerIntellect.GetControlKeyStrength(GameControlKeys.Right);
                        if (vec.X < 0)
                        {
                            vec = -vec;
                        }
                        horizontalAngle = MathFunctions.ATan(vec.Y, vec.X);

                        verticalAngle = playerIntellect.LookDirection.Vertical;
                    }

                    tree.SetParameterValue("weaponHorizontalAngle", horizontalAngle.InDegrees());
                    tree.SetParameterValue("weaponVerticalAngle", verticalAngle.InDegrees());
                }
            }
        }
示例#4
0
        void MomentaryTurnToPositionUpdate(Vec3 turnToPosition)
        {
            if ((turnToPosition - Position).Length() < 4.0f)
            {
                Vec3 dir = (turnToPosition - Position).GetNormalize();
                turnToPosition += dir * 10f;
            }

            Vec3  diff = (turnToPosition - Position);
            Quat  collisionRotation;
            float distance = diff.LengthFast();

            Radian horizontalAngle = MathFunctions.ATan(diff.Y, diff.X);
            Radian verticalAngle   = MathFunctions.ATan(diff.Z, diff.ToVec2().Length());

            collisionRotation = new Angles(0, 0, -horizontalAngle.InDegrees()).ToQuat();

            collisionRotation *= new Angles(0, verticalAngle.InDegrees(), 0).ToQuat();

            Rotation = Quat.Slerp(Rotation, collisionRotation, Type.HomingCorrection);
        }
示例#5
0
        private Ladder FindLadder(bool alreadyAttachedToSomeLadder, bool wantMove, SphereDir lookDirection)
        {
            float fromPositionToFloorDistance = (Type.Height - Type.WalkUpHeight) * .5f + Type.WalkUpHeight;

            Ladder result = null;

            Bounds bounds = MapBounds;

            bounds.Expand(1);

            Map.Instance.GetObjects(bounds, delegate(MapObject mapObject)
            {
                if (result != null)
                {
                    return;
                }

                Ladder ladder = mapObject as Ladder;
                if (ladder == null)
                {
                    return;
                }
                //if (ladder.IsInvalidOrientation())
                //   return;

                Line line = ladder.GetClimbingLine();

                Vec3 projected = MathUtils.ProjectPointToLine(line.Start, line.End, Position);

                //check by distance
                float distanceToLine = (projected - Position).Length();
                if (distanceToLine > .5f)
                {
                    return;
                }

                //check by up and down limits
                if (alreadyAttachedToSomeLadder)
                {
                    if (projected.Z > line.End.Z + fromPositionToFloorDistance)
                    {
                        return;
                    }
                }
                else
                {
                    if (projected.Z > line.End.Z + fromPositionToFloorDistance * .5f)
                    {
                        return;
                    }
                }
                if (projected.Z < line.Start.Z)
                {
                    return;
                }

                //check by direction
                bool isHorizontallyOrientedToLadder;
                {
                    Vec2 ladderDirection2          = ladder.Rotation.GetForward().ToVec2();
                    Vec2 direction2                = Rotation.GetForward().ToVec2();
                    Radian angle                   = MathUtils.GetVectorsAngle(ladderDirection2, direction2);
                    isHorizontallyOrientedToLadder = angle.InDegrees() < 70;
                }

                if (Math.Abs(new Radian(lookDirection.Vertical).InDegrees()) < 45 &&
                    !isHorizontallyOrientedToLadder)
                {
                    if (alreadyAttachedToSomeLadder)
                    {
                        if (wantMove)
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                //got ladder
                result = ladder;
            });

            return(result);
        }
示例#6
0
 void UpdateRotation()
 {
     Rotation = new Angles(0, 0, -rotationAngle.InDegrees()).ToQuat();
 }