gamemode spawning
This commit is contained in:
@@ -41,6 +41,13 @@ namespace Game
|
||||
float deltaY = position.Y - lastPosition.Y;
|
||||
//if (Mathf.Abs(deltaY) < 10f)
|
||||
if (deltaY > 0)
|
||||
{
|
||||
if (deltaY > 100f)
|
||||
{
|
||||
// Teleported, snap instantly
|
||||
UpdatePosition(position);
|
||||
}
|
||||
else
|
||||
{
|
||||
const float catchUpDistance = 10f;
|
||||
const float catchUpMinMultip = 0.25f;
|
||||
@@ -55,6 +62,7 @@ namespace Game
|
||||
UpdatePosition(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdatePosition(position);
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Cabrito
|
||||
|
||||
#if FLAX_EDITOR
|
||||
ScriptsBuilder.ScriptsReload += Destroy;
|
||||
Editor.Instance.StateMachine.StateChanged += OnEditorStateChanged;
|
||||
Editor.Instance.PlayModeEnd += OnEditorPlayModeChanged;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -100,15 +100,14 @@ 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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Actor>().Where(x => x.Name.StartsWith("PlayerSpawn_")).ToArray();
|
||||
Console.Print($"found {spawns.Length} spawns");
|
||||
|
||||
var randomSpawn = spawns.First();
|
||||
|
||||
PlayerActor localPlayerActor = Level.FindActor<PlayerActor>();
|
||||
|
||||
localPlayerActor.Teleport(randomSpawn.Position + new Vector3(0f, 4.1f, 0f), randomSpawn.Orientation.EulerAngles);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -761,10 +761,11 @@ namespace Game
|
||||
Actor spawn = worldSpawnActor.AddChild<Actor>();
|
||||
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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<PlayerMovement>();
|
||||
playerRigidBody = FindActor<RigidBody>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<RigidBody>();
|
||||
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<Camera>();
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user