public void CharacterTest1() { var game = new CharacterTest(); game.Script.AddTask(async() => { game.ScreenShotAutomationEnabled = false; await game.Script.NextFrame(); await game.Script.NextFrame(); var character = game.SceneSystem.SceneInstance.RootScene.Entities.First(ent => ent.Name == "Character"); var controller = character.Get <CharacterComponent>(); var simulation = controller.Simulation; //let the controller land var twoSeconds = 120; while (twoSeconds-- > 0) { await game.Script.NextFrame(); } Assert.True(controller.IsGrounded); controller.Jump(); await game.Script.NextFrame(); Assert.False(controller.IsGrounded); //let the controller land twoSeconds = 120; while (twoSeconds-- > 0) { await game.Script.NextFrame(); } Assert.True(controller.IsGrounded); var currentPos = character.Transform.Position; controller.SetVelocity(Vector3.UnitX * 3); await game.Script.NextFrame(); Assert.NotEqual(currentPos, character.Transform.Position); var target = currentPos + Vector3.UnitX * 3 * simulation.FixedTimeStep; Assert.Equal(character.Transform.Position.X, target.X, 15f); Assert.Equal(character.Transform.Position.Y, target.Y, 15f); Assert.Equal(character.Transform.Position.Z, target.Z, 15f); currentPos = character.Transform.Position; await game.Script.NextFrame(); Assert.NotEqual(currentPos, character.Transform.Position); target = currentPos + Vector3.UnitX * 3 * simulation.FixedTimeStep; Assert.Equal(character.Transform.Position.X, target.X, 15f); Assert.Equal(character.Transform.Position.Y, target.Y, 15f); Assert.Equal(character.Transform.Position.Z, target.Z, 15f); controller.SetVelocity(Vector3.Zero); await game.Script.NextFrame(); currentPos = character.Transform.Position; await game.Script.NextFrame(); Assert.Equal(currentPos, character.Transform.Position); var collider = game.SceneSystem.SceneInstance.RootScene.Entities.First(ent => ent.Name == "Collider").Get <StaticColliderComponent>(); game.Script.AddTask(async() => { var fourSeconds = 240; while (fourSeconds-- > 0) { await game.Script.NextFrame(); } Assert.True(false, "Character controller never collided with test collider."); }); controller.SetVelocity(Vector3.UnitX * 2.5f); await collider.NewCollision(); game.Exit(); }); RunGameTest(game); }
/// <summary> /// This is useful if you want to run all the tests on your own machine and compare images /// </summary> public static void Main() { using (var game = new ColliderShapesTest()) { game.ColliderShapesTest1(); } using (var game = new CharacterTest()) { game.CharacterTest1(); } using (var game = new SkinnedTest()) { game.SkinnedTest1(); } }