From e975d1dc00dd5dc34bfe3c332628c2208247f31f Mon Sep 17 00:00:00 2001 From: danielbrownmsm Date: Sat, 30 Nov 2024 13:33:01 -0600 Subject: [PATCH] made orbit/follow camera per #9 just need to make a keybind to swap between them and the auto camera view --- Assets/Scenes/menu.unity | 45 ++++++++++++++++++++++++++++++++++++ Assets/Scripts/Robot.cs | 31 +++++++++++++------------ Assets/Scripts/ui/MenuUI.cs | 2 +- Assets/Scripts/ui/PauseUI.cs | 2 +- 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/Assets/Scenes/menu.unity b/Assets/Scenes/menu.unity index ab9eec3..58490d8 100644 --- a/Assets/Scenes/menu.unity +++ b/Assets/Scenes/menu.unity @@ -194,6 +194,7 @@ GameObject: - component: {fileID: 1061402856} - component: {fileID: 1061402855} - component: {fileID: 1061402854} + - component: {fileID: 1061402857} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -275,6 +276,50 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1061402857 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1061402853} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3} + m_Name: + m_EditorClassIdentifier: + m_RenderShadows: 1 + m_RequiresDepthTextureOption: 2 + m_RequiresOpaqueTextureOption: 2 + m_CameraType: 0 + m_Cameras: [] + m_RendererIndex: -1 + m_VolumeLayerMask: + serializedVersion: 2 + m_Bits: 1 + m_VolumeTrigger: {fileID: 0} + m_VolumeFrameworkUpdateModeOption: 2 + m_RenderPostProcessing: 0 + m_Antialiasing: 0 + m_AntialiasingQuality: 2 + m_StopNaN: 0 + m_Dithering: 0 + m_ClearDepth: 1 + m_AllowXRRendering: 1 + m_AllowHDROutput: 1 + m_UseScreenCoordOverride: 0 + m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0} + m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0} + m_RequiresDepthTexture: 0 + m_RequiresColorTexture: 0 + m_Version: 2 + m_TaaSettings: + m_Quality: 3 + m_FrameInfluence: 0.1 + m_JitterScale: 1 + m_MipBias: 0 + m_VarianceClampScale: 0.9 + m_ContrastAdaptiveSharpening: 0 --- !u!1 &1142981717 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Robot.cs b/Assets/Scripts/Robot.cs index 411add8..9884606 100644 --- a/Assets/Scripts/Robot.cs +++ b/Assets/Scripts/Robot.cs @@ -24,11 +24,11 @@ public class Robot : MonoBehaviour private float steer = 0.0f; // mouse-controlled orbit camera spherical coordinates stuff - private float theta = 0.0f; // controls azimuth - private float phi = 0.0f; // controls altitude - private float rho = Mathf.Sqrt((-15)*(-15) + (57)*57 + 47*47); //FIXME this should be configurable and not hard-coded + public float theta = 0.0f; // controls azimuth + public float phi = 0.0f; // controls altitude + private float rho = Mathf.Sqrt((-15)*(-15) + (57)*57 + 47*47) + 10; //FIXME this should be configurable and not hard-coded private Vector3 mousePos = new Vector3(0, 0, 0); - private const float mouseScaleFactor = 100f; //TODO tune this, configurable idk + private const float mouseScaleFactor = 400f; //TODO tune this, configurable idk private Vector3 initialPosition = new Vector3(47f, .6f, 26f); private Vector3 initialHeading = new Vector3(0, 90, 0); @@ -131,19 +131,23 @@ void Start() // theta = 0=2pi is at the front of the robot, theta = pi is at the back??? // although maybe we don't want them to go below the ground? also, what about barrels? do we clip through barrels? are we allowing zoom in and out? // I don't want to, but it might be cool - theta += Input.mousePositionDelta.x / mouseScaleFactor; - phi += Input.mousePositionDelta.y / mouseScaleFactor; + theta -= Input.mousePositionDelta.x / mouseScaleFactor; + phi += Input.mousePositionDelta.y / mouseScaleFactor; // minus because phi is from the top/y axis and not from the x-z plane + + if (theta > 2*Mathf.PI) { + theta -= 2*Mathf.PI; + } else if (theta < 0) { + theta += 2*Mathf.PI; + } - theta = Mathf.Clamp(theta, 0.0f, 2*Mathf.PI); - phi = Mathf.Clamp(phi, 0.0f, Mathf.PI); - // phi %= Mathf.PI; // keep phi between [0, pi] - // theta %= 2*Mathf.PI; // keep theta between [0, 2pi] + phi = Mathf.Clamp(phi, 0.0f, Mathf.PI/2); - thirdPersonCamera.transform.localPosition = new Vector3(rho*Mathf.Cos(theta)*Mathf.Sin(phi), rho*Mathf.Sin(theta)*Mathf.Sin(phi), rho*Mathf.Cos(phi)); + thirdPersonCamera.transform.localPosition = new Vector3(rho*Mathf.Cos(theta)*Mathf.Sin(phi), rho*Mathf.Cos(phi), rho*Mathf.Sin(theta)*Mathf.Sin(phi)); // not sure how to calculate the rotation the camera should be at. probably involes trig. at phi=0 the camera should be tilted down by 90 degrees. at phi = pi/2 the camera should be level with the horizon // at theta = 0 the camera should be 180 degrees (facing the robot), and theta = pi the camera should be facing the back of the robot (in the forwards direction) - thirdPersonCamera.transform.localEulerAngles = new Vector3(Mathf.Rad2Deg*Mathf.Cos(theta), 0, Mathf.Rad2Deg*Mathf.Sin(theta)); //TODO + thirdPersonCamera.transform.localEulerAngles = new Vector3(90 - Mathf.Rad2Deg*phi, 270 - Mathf.Rad2Deg*theta, 0); //TODO + // thirdPersonCamera.transform.localEulerAngles = new Vector3(Mathf.Rad2Deg*Mathf.Cos(theta), 0, Mathf.Rad2Deg*Mathf.Sin(theta)); //TODO break; case "auto": @@ -157,9 +161,6 @@ void Start() thirdPersonCamera.transform.eulerAngles = new Vector3(90, 0, 90); // this is somewhat shaky for some reason, in the future probably best to implement as a separate camera and just sitch to it while disabling original 3rd person // when its not rendering and then disabling this camera and going back to the 3rd person one whenver we swap to like fixed for instance - break; - case "follow": - //TODO make camera like scrap mechanic follow break; case "cinematic": //TODO this is for issue #11, not our problem right now diff --git a/Assets/Scripts/ui/MenuUI.cs b/Assets/Scripts/ui/MenuUI.cs index ac9829a..2adfd76 100644 --- a/Assets/Scripts/ui/MenuUI.cs +++ b/Assets/Scripts/ui/MenuUI.cs @@ -45,7 +45,7 @@ private void SetupCallbacks() manualControlToggle.value = SettingsManager.IntToBool(PlayerPrefs.GetInt("manualEnabled", 0)); fieldOrientedControl.value = SettingsManager.IntToBool(PlayerPrefs.GetInt("fieldOriented", 0)); showHUD.value = SettingsManager.IntToBool(PlayerPrefs.GetInt("showHUD", 1)); - cameraDropdown.value = PlayerPrefs.GetString("cameraDropdown", "fixed"); + cameraDropdown.value = PlayerPrefs.GetString("cameraView", "fixed"); positionSlider.value = PlayerPrefs.GetFloat("positionOffset", 0.0f); headingSlider.value = PlayerPrefs.GetFloat("initialHeading", 0.0f); diff --git a/Assets/Scripts/ui/PauseUI.cs b/Assets/Scripts/ui/PauseUI.cs index 5f044f5..ffc700e 100644 --- a/Assets/Scripts/ui/PauseUI.cs +++ b/Assets/Scripts/ui/PauseUI.cs @@ -37,7 +37,7 @@ private void SetupCallbacks() fieldOrientedControl.value = SettingsManager.fieldOriented; showHUD.value = SettingsManager.showHUD; - cameraDropdown.choices = new List { "fixed", "mouse", "auto", "bird's eye", "follow", "cinematic"}; + cameraDropdown.choices = new List { "fixed", "mouse", "auto", "bird's eye", "cinematic"}; cameraDropdown.value = SettingsManager.cameraView; manualControlToggle.RegisterCallback(ToggleManualControl);