public void AddForce(Force f)
        {
            this.FNET += f.f;
            this.currForces.Add(f);

            var tau = Vector3.Cross(f.con.ToVector3(), f.f.ToVector3());
            this.TNET += tau.Z;
        }
Пример #2
0
        void Player_StateChanged(object previous)
        {
            // Below Code will only work when friction is fixed
            /*
            var prevState = (ActorState)previous;
            if (State.Name == WalkingState.Name)
                PolyBody.Velocity += Vector2.UnitX * MaxWalkSpeed * FacingDirection;
            if (prevState.Name == WalkingState.Name)
                PolyBody.Velocity -= Vector2.UnitX * MaxWalkSpeed * FacingDirection;
            */

            if (State.Name == WalkingState.Name)
            {
                if (MaxWalkSpeed - Math.Abs(PolyBody.Velocity.X) > 0)
                {
                    PolyBody.Velocity += FacingDirection * new Vector2(MaxWalkSpeed / 10, 0);
                   // move.f = WalkForce * FacingDirection * Vector2.UnitX;
                }
                else if (Math.Abs(PolyBody.Velocity.X) >= MaxWalkSpeed)
                {
                    PolyBody.Velocity = new Vector2(FacingDirection.X * MaxWalkSpeed, PolyBody.Velocity.Y);
                }
                //PolyBody.AddForce(move);

            }
            else if (State.Name == StandingState.Name)
            {
                PolyBody.Velocity *= Vector2.UnitY;
            }

            ////You can double jump, triple jump, or even n jump. Need to figure out a way to fix this.
            if (State.Name == JumpingState.Name && canChangeState)
            {
                    Force jump = new Force();
                    jump.t = ForceType.Spring;
                    jump.f = Vector2.UnitY * JumpForce;
                    PolyBody.AddForce(jump);
                    canChangeState = false;

            }
            else
            {
                GraphicsEngine.ResetAnimations();
            }
        }