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);
                }
            }
        }
Beispiel #2
0
        protected override void OnUpdateBaseAnimation()
        {
            base.OnUpdateBaseAnimation();

            //walk animation
            if (IsOnGround() && GroundRelativeVelocity.ToVec2().LengthSqr() > .3f)
            {
                float velocity = (Rotation.GetInverse() * GroundRelativeVelocity).X *
                                 Type.WalkAnimationVelocityMultiplier;
                UpdateBaseAnimation(Type.WalkAnimationName, true, true, velocity);
                return;
            }

            //idle animation
            {
                UpdateBaseAnimation(Type.IdleAnimationName, true, true, 1);
                return;
            }
        }
        void UpdateFirstPersonArmsAttachedMesh(MapObjectAttachedMesh armsAttachedMesh, Camera camera)
        {
            //update animation tree
            if (EntitySystemWorld.Instance.Simulation && !EntitySystemWorld.Instance.SystemPauseOfSimulation)
            {
                AnimationTree tree = armsAttachedMesh.AnimationTree;
                if (tree != null)
                {
                    bool onGround = GetElapsedTimeSinceLastGroundContact() < .2f;                    //IsOnGround();

                    bool  move      = false;
                    float moveSpeed = 0;
                    if (onGround && GroundRelativeVelocitySmooth.ToVec2().Length() > .05f)
                    {
                        move      = true;
                        moveSpeed = GroundRelativeVelocity.ToVec2().Length();
                    }

                    tree.SetParameterValue("move", move ? 1 : 0);
                    tree.SetParameterValue("run", move && IsNeedRun() ? 1 : 0);
                    tree.SetParameterValue("moveSpeed", moveSpeed);
                    float moveSpeedFactor = moveSpeed / Type.RunForwardMaxSpeed;
                    if (moveSpeedFactor > 1)
                    {
                        moveSpeedFactor = 1;
                    }
                    tree.SetParameterValue("moveSpeedFactor", moveSpeedFactor);
                }
            }

            //update scene node
            armsAttachedMesh.SceneNode.Position = camera.Position + camera.Rotation * armsAttachedMesh.TypeObject.Position;
            armsAttachedMesh.SceneNode.Rotation = camera.Rotation * armsAttachedMesh.TypeObject.Rotation;

            //use this code to look arms from another point of view. Useful for calibration position of attached weapon.
            //armsAttachedMesh.SceneNode.Position = new Vec3( 0, 0, 2 ) + Quat.Identity * armsAttachedMesh.TypeObject.Position;
            //armsAttachedMesh.SceneNode.Rotation = Quat.Identity * armsAttachedMesh.TypeObject.Rotation;
        }