Skip to content

Commit

Permalink
made orbit/follow camera per #9
Browse files Browse the repository at this point in the history
just need to make a keybind to swap between them and the auto camera view
  • Loading branch information
danielbrownmsm committed Nov 30, 2024
1 parent 417ee97 commit e975d1d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 17 deletions.
45 changes: 45 additions & 0 deletions Assets/Scenes/menu.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 16 additions & 15 deletions Assets/Scripts/Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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":
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/ui/MenuUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/ui/PauseUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void SetupCallbacks()
fieldOrientedControl.value = SettingsManager.fieldOriented;
showHUD.value = SettingsManager.showHUD;

cameraDropdown.choices = new List<string> { "fixed", "mouse", "auto", "bird's eye", "follow", "cinematic"};
cameraDropdown.choices = new List<string> { "fixed", "mouse", "auto", "bird's eye", "cinematic"};
cameraDropdown.value = SettingsManager.cameraView;

manualControlToggle.RegisterCallback<ClickEvent>(ToggleManualControl);
Expand Down

0 comments on commit e975d1d

Please sign in to comment.