public override void Update() { int drawX = 800, drawY = 600; StopOrResumeAnimations(drawX, drawY += 20); AdjustAnimationSpeed(drawX, drawY += 20); DebugText.Print("I to start playing Idle", new Int2(drawX, drawY += 20)); if (Input.IsKeyPressed(Keys.I)) { latestAnimation = animation.Play("Idle"); latestAnimation.TimeFactor = AnimationSpeed; } DebugText.Print("R to crossfade to Run", new Int2(drawX, drawY += 20)); if (Input.IsKeyPressed(Keys.R)) { latestAnimation = animation.Crossfade("Run", TimeSpan.FromSeconds(0.5)); latestAnimation.TimeFactor = AnimationSpeed; } // We can crossfade to a punch animation, but only if it is not already playing DebugText.Print("P to crossfade to Punch and play it once", new Int2(drawX, drawY += 20)); if (Input.IsKeyPressed(Keys.P) && !animation.IsPlaying("Punch")) { latestAnimation = animation.Crossfade("Punch", TimeSpan.FromSeconds(0.1)); latestAnimation.RepeatMode = AnimationRepeatMode.PlayOnce; latestAnimation.TimeFactor = AnimationSpeed; } // When the punch animation is the latest animation, but it is no longer playing, we set a new animation if (latestAnimation.Name == "Punch" && !animation.IsPlaying("Punch")) { latestAnimation = animation.Play("Idle"); latestAnimation.RepeatMode = AnimationRepeatMode.LoopInfinite; latestAnimation.TimeFactor = AnimationSpeed; } }
private void UpdateMovement() { MoveDirection = Entity.Transform.WorldMatrix.Forward.XY(); var Movement = new Vector3(0, 0, 0); float deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds; MouseDelta = Input.Mouse.Delta; var rotation = Rotation(MouseDelta.X, CurrentRotation); //Rotate player entity //Entity.Transform.Rotation = rotation; CurrentRotation = Entity.Transform.Rotation; //Sets forward velocity in rotation matrix Matrix tempMatrix; Matrix.RotationQuaternion(ref rotation, out tempMatrix); if (Input.IsKeyDown(Keys.S)) { Movement = -tempMatrix.Backward; MoveDirection += -Vector2.UnitY; } if (Input.IsKeyDown(Keys.W)) { Movement = -tempMatrix.Forward; MoveDirection += Vector2.UnitY; } if (Input.IsKeyDown(Keys.A)) { Movement = -tempMatrix.Left; MoveDirection += -Vector2.UnitX; } if (Input.IsKeyDown(Keys.D)) { Movement = -tempMatrix.Right; MoveDirection += Vector2.UnitX; } var xx = new Vector3(MoveDirection.X, 0, MoveDirection.Y); var l = MoveDirection.Length(); xx *= l; RB.SetVelocity(xx /** deltaTime*/); var yawOrientation = MathUtil.RadiansToDegrees((float)Math.Atan2(-xx.Z, xx.X) + MathUtil.PiOverTwo); Entity.Transform.Rotation = Quaternion.RotationYawPitchRoll(MathUtil.DegreesToRadians(yawOrientation), 0, 0); if (!Movement.Equals(Vector3.Zero)) { if (!animComponent.IsPlaying("walk")) { animComponent.Crossfade("walk", TimeSpan.FromSeconds(0.5)); } } else { if (!animComponent.IsPlaying("idle")) { animComponent.Crossfade("idle", TimeSpan.FromSeconds(0.5)); } } // We store the local and world position of our entity's tranform in a Vector3 variable Vector3 localPosition = Camera.Entity.Transform.Position; Vector3 worldPosition = Entity.Transform.WorldMatrix.Forward; // We disaply the entity's name and its local and world position on screen DebugText.Print(Camera.Entity.Name + " - local position: " + localPosition, new Int2(400, 450)); DebugText.Print(Entity.Name + " - world position: " + worldPosition, new Int2(400, 470)); DebugText.Print($"{Movement.Z}: Z - {Movement.X} : X {rotation} : Rotation", new Int2(20, 45)); }