diff --git a/Source/Game/Camera/CameraSpring.cs b/Source/Game/Camera/CameraSpring.cs index 416049b..e802194 100644 --- a/Source/Game/Camera/CameraSpring.cs +++ b/Source/Game/Camera/CameraSpring.cs @@ -42,17 +42,25 @@ namespace Game //if (Mathf.Abs(deltaY) < 10f) if (deltaY > 0) { - const float catchUpDistance = 10f; - const float catchUpMinMultip = 0.25f; - percY = Mathf.Abs(deltaY) / catchUpDistance; - percY = Mathf.Min(1.0f, percY + catchUpMinMultip); - percY *= percY; + if (deltaY > 100f) + { + // Teleported, snap instantly + UpdatePosition(position); + } + else + { + const float catchUpDistance = 10f; + const float catchUpMinMultip = 0.25f; + percY = Mathf.Abs(deltaY) / catchUpDistance; + percY = Mathf.Min(1.0f, percY + catchUpMinMultip); + percY *= percY; - float adjustSpeed = speed * Time.DeltaTime * percY; + float adjustSpeed = speed * Time.DeltaTime * percY; - position.Y = lastPosition.Y; //-= deltaY; - position.Y = Mathf.MoveTowards(position.Y, targetPosition.Y, adjustSpeed); - UpdatePosition(position); + position.Y = lastPosition.Y; //-= deltaY; + position.Y = Mathf.MoveTowards(position.Y, targetPosition.Y, adjustSpeed); + UpdatePosition(position); + } } } else diff --git a/Source/Game/Console/Console.cs b/Source/Game/Console/Console.cs index 57ae28b..cc387b7 100644 --- a/Source/Game/Console/Console.cs +++ b/Source/Game/Console/Console.cs @@ -87,7 +87,7 @@ namespace Cabrito #if FLAX_EDITOR ScriptsBuilder.ScriptsReload += Destroy; - Editor.Instance.StateMachine.StateChanged += OnEditorStateChanged; + Editor.Instance.PlayModeEnd += OnEditorPlayModeChanged; #endif } @@ -100,18 +100,17 @@ namespace Cabrito #if FLAX_EDITOR ScriptsBuilder.ScriptsReload -= Destroy; - Editor.Instance.StateMachine.StateChanged -= OnEditorStateChanged; + Editor.Instance.PlayModeEnd -= OnEditorPlayModeChanged; #endif } } #if FLAX_EDITOR - private static void OnEditorStateChanged() + private static void OnEditorPlayModeChanged() { - if (!Editor.Instance.StateMachine.IsPlayMode) - // Clear console buffer when leaving play mode - if (instance != null) - Clear(); + // Clear console buffer when leaving play mode + if (instance != null) + Clear(); } #endif diff --git a/Source/Game/Console/ConsolePlugin.cs b/Source/Game/Console/ConsolePlugin.cs index 391caee..af42765 100644 --- a/Source/Game/Console/ConsolePlugin.cs +++ b/Source/Game/Console/ConsolePlugin.cs @@ -22,15 +22,12 @@ namespace Game public override void Initialize() { base.Initialize(); - Debug.Log("ConsolePlugin Initialize"); - Console.Init(); } public override void Deinitialize() { base.Deinitialize(); - Debug.Log("ConsolePlugin Deinitialize"); } } @@ -43,13 +40,13 @@ namespace Game public override void Initialize() { - Debug.Log("ConsoleEditorPlugin Initialize"); + base.Initialize(); Console.Init(); } public override void Deinitialize() { - Debug.Log("ConsoleEditorPlugin Deinitialize"); + base.Deinitialize(); } } #endif diff --git a/Source/Game/GameMode/GameModeManager.cs b/Source/Game/GameMode/GameModeManager.cs index 6ec4caa..5226037 100644 --- a/Source/Game/GameMode/GameModeManager.cs +++ b/Source/Game/GameMode/GameModeManager.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using FlaxEngine; using FlaxEngine.Networking; using Console = Cabrito.Console; @@ -11,7 +12,6 @@ namespace Game { NetworkManager.OnMessage += OnClientConnected; Level.SceneLoaded += OnLevelLoaded; - Console.Print("level was loaded: " + Level.IsAnySceneLoaded); } public static void Cleanup() @@ -28,6 +28,18 @@ namespace Game public static bool OnClientConnected(NetworkMessage message) { Console.Print("client connected"); + + + + var spawns = Level.GetActors().Where(x => x.Name.StartsWith("PlayerSpawn_")).ToArray(); + Console.Print($"found {spawns.Length} spawns"); + + var randomSpawn = spawns.First(); + + PlayerActor localPlayerActor = Level.FindActor(); + + localPlayerActor.Teleport(randomSpawn.Position + new Vector3(0f, 4.1f, 0f), randomSpawn.Orientation.EulerAngles); + return true; } } diff --git a/Source/Game/Level/Q3MapImporter.cs b/Source/Game/Level/Q3MapImporter.cs index 05f719c..34bee28 100644 --- a/Source/Game/Level/Q3MapImporter.cs +++ b/Source/Game/Level/Q3MapImporter.cs @@ -761,10 +761,11 @@ namespace Game Actor spawn = worldSpawnActor.AddChild(); spawn.Name = "PlayerSpawn_" + playerSpawnIndex; spawn.LocalPosition = ParseOrigin(entity.properties["origin"]); - if (entity.properties.ContainsKey("angle")) - spawn.Orientation = ParseAngle(entity.properties["angle"]); - spawn.Tag = "PlayerSpawn"; + string angleStr = entity.properties.ContainsKey("angle") ? entity.properties["angle"] : "0"; + spawn.Orientation = ParseAngle(angleStr); + + //spawn.Tag = "PlayerSpawn"; playerSpawnIndex++; } @@ -784,7 +785,14 @@ namespace Game private static Quaternion ParseAngle(string origin) { string[] angles = origin.Split(' '); - return Quaternion.Euler(new Vector3(0f, float.Parse(angles[0]), 0f)); + //Console.Print("parseangle: " + new Vector3(0f, float.Parse(angles[0]) + 45f, 0f).ToString()); + return Quaternion.Euler(new Vector3(0f, float.Parse(angles[0]) + 90f, 0f)); + } + + private static Vector3 ParseAngleEuler(string origin) + { + string[] angles = origin.Split(' '); + return new Vector3(0f, float.Parse(angles[0]) + 45f, 0f); } public override void OnDestroy() diff --git a/Source/Game/Network/NetworkManager.cs b/Source/Game/Network/NetworkManager.cs index 8beb52f..5ede73f 100644 --- a/Source/Game/Network/NetworkManager.cs +++ b/Source/Game/Network/NetworkManager.cs @@ -63,15 +63,17 @@ namespace Game else { StartServer(); + ServerAddress = "localhost"; + ConnectServer(); } #endif initialized = true; - GameModeManager.Init(); // FIXME - #if FLAX_EDITOR Editor.Instance.PlayModeEnd += Cleanup; #endif + + GameModeManager.Init(); // FIXME } public static void Cleanup() @@ -96,8 +98,10 @@ namespace Game #if FLAX_EDITOR Editor.Instance.PlayModeEnd -= Cleanup; - GameModeManager.Cleanup(); + GameModeManager.Cleanup(); // FIXME #endif + + initialized = false; } private static void OnNetworkMessage(NetworkEvent networkEvent) diff --git a/Source/Game/Network/NetworkManagerPlugin.cs b/Source/Game/Network/NetworkManagerPlugin.cs index c30fbf4..0d90b95 100644 --- a/Source/Game/Network/NetworkManagerPlugin.cs +++ b/Source/Game/Network/NetworkManagerPlugin.cs @@ -2,6 +2,7 @@ using FlaxEngine; using Console = Cabrito.Console; #if FLAX_EDITOR +using System.Diagnostics; using FlaxEditor; #endif @@ -22,16 +23,13 @@ namespace Game public override void Initialize() { base.Initialize(); - Debug.Log("NetworkManagerPlugin Initialize"); Console.Init(); - NetworkManager.Init(); } public override void Deinitialize() { base.Deinitialize(); - Debug.Log("NetworkManagerPlugin Deinitialize"); } } @@ -44,15 +42,14 @@ namespace Game public override void Initialize() { - Debug.Log("NetworkManagerEditorPlugin Initialize"); + base.Initialize(); Console.Init(); - - NetworkManager.Init(); + //NetworkManager.Init(); } public override void Deinitialize() { - Debug.Log("NetworkManagerEditorPlugin Deinitialize"); + base.Deinitialize(); } } #endif diff --git a/Source/Game/Player/PlayerActor.cs b/Source/Game/Player/PlayerActor.cs index 38e986e..2502a82 100644 --- a/Source/Game/Player/PlayerActor.cs +++ b/Source/Game/Player/PlayerActor.cs @@ -36,6 +36,9 @@ namespace Game public class PlayerActor : RigidBody { + private PlayerMovement playerMovement; + private RigidBody playerRigidBody; + public PlayerActor() { // Default internal values for RigidBody @@ -45,5 +48,29 @@ namespace Game AngularDamping = 0f; Constraints = RigidbodyConstraints.LockRotation; } + + public override void OnBeginPlay() + { + base.OnBeginPlay(); + + playerMovement = FindScript(); + playerRigidBody = FindActor(); + } + + public void SetPosition(Vector3 newPosition) + { + Position = newPosition; + } + + public void SetRotation(Vector3 eulerAngles) + { + playerMovement.ResetRotation(eulerAngles); + } + + public void Teleport(Vector3 newPosition, Vector3 eulerAngles) + { + SetPosition(newPosition); + SetRotation(eulerAngles); + } } } \ No newline at end of file diff --git a/Source/Game/Player/PlayerMovement.cs b/Source/Game/Player/PlayerMovement.cs index d01c7e3..8e5e105 100644 --- a/Source/Game/Player/PlayerMovement.cs +++ b/Source/Game/Player/PlayerMovement.cs @@ -96,6 +96,7 @@ namespace Game [ReadOnly] public bool onGround; private RigidBody rigidBody; + private Actor cameraHolder; private Actor rootActor; private float startupTime; @@ -155,9 +156,9 @@ namespace Game Engine.RequestExit(); }; - rootActor = Actor.GetChild(0); - + rootActor = Actor.GetChild("RootActor"); rigidBody = Actor.As(); + cameraHolder = rootActor.GetChild("CameraHolder"); //rigidBody.CollisionEnter += OnCollisionEnter; //rigidBody.TriggerEnter += OnTriggerEnter; @@ -205,13 +206,19 @@ namespace Game public override void OnStart() { - Vector3 initialEulerAngles = Actor.Orientation.EulerAngles; - viewPitch = initialEulerAngles.X; - viewYaw = initialEulerAngles.Y; - viewRoll = initialEulerAngles.Z; + ResetRotation(Actor.Orientation.EulerAngles); + } + + public void ResetRotation(Vector3 eulerAngles) + { + viewPitch = eulerAngles.X; + viewYaw = eulerAngles.Y; + viewRoll = eulerAngles.Z; viewPitchLastFrame = viewPitch; viewYawLastFrame = viewYaw; viewRollLastFrame = viewRoll; + + SetCameraEulerAngles(new Vector3(viewYaw, viewPitch, viewRoll)); } public override void OnUpdate() @@ -348,9 +355,6 @@ namespace Game private void SetCameraEulerAngles(Vector3 viewAngles) { - //Camera camera = rootActor.GetChild(); - Actor cameraHolder = rootActor.GetChild("CameraHolder"); - // Root orientation must be set first rootActor.Orientation = Quaternion.Euler(0, viewAngles.X, 0); cameraHolder.Orientation = Quaternion.Euler(viewAngles.Y, viewAngles.X, viewAngles.Z);