Skip to content
This repository has been archived by the owner on Apr 30, 2023. It is now read-only.

Commit

Permalink
Implement save and loading of transform when toggling noclip
Browse files Browse the repository at this point in the history
Fixed clamping of float variables
  • Loading branch information
abarichello committed May 19, 2019
1 parent 71d7a6d commit 5389834
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ This mod restores the developer's original debug mode and provides camera moveme
<a href="http://yt.barichello.me"><img src="https://i.imgur.com/pBfHQym.png" width="800"></a>
</div>


## How to Install
Download the DLL from the [releases tab](https://github.com/aBARICHELLO/far-lone-sails-noclip/releases) and replace the original in the game instalation folder.<br>
(default is `C:\Program Files (x86)\Steam\steamapps\common\FAR Lone Sails\Game\FarLoneSails_Data\Managed`).<br>
To remove the mod simply delete the replaced DLL and ask Steam to verify the game's integrity, downloading back the original file.

## Usage

#### Debug mode
Expand All @@ -30,7 +36,7 @@ Shift+I|Force reset vehicle
#### Noclip
Hotkey|Action
-|-
Numlock|Toggle noclip mode
**Numlock**|**Toggle noclip mode**
Scroll wheel up|Increase FOV
Scroll wheel down|Reduce FOV
Home/End|Forwards/Backwards
Expand Down
34 changes: 24 additions & 10 deletions src/CameraEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ void Update() {
if (Input.GetKeyDown(KeyCode.Numlock)) {
this.noclip = !this.noclip;
if (noclip) {
// TODO: Save starting FOV
this.SaveCameraTransform();
this.camera.fov = noclipFOV;
} else {
// TODO: Restore starting FOV
this.LoadCameraTransform();
}
}

Expand All @@ -40,12 +41,12 @@ void Noclip() {
if (Input.GetAxis("Mouse ScrollWheel") > 0f) {
this.camera.fov += this.fovChange;
}
Mathf.Clamp(this.camera.fov, 0f, 300f);
this.camera.fov = Mathf.Clamp(this.camera.fov, 0f, 130f);

// Camera Rotation
this.cameraXAngle += 0.5f * Input.GetAxis("Mouse X");
this.cameraYAngle -= 0.5f * Input.GetAxis("Mouse Y");
Mathf.Clamp(this.cameraYAngle, -50f, 50f);
this.cameraYAngle = Mathf.Clamp(this.cameraYAngle, -50f, 50f);
this.camera.transform.eulerAngles = new Vector3(this.cameraYAngle, this.cameraXAngle, 0f);

// Position
Expand Down Expand Up @@ -85,16 +86,29 @@ void Noclip() {
}
}

void SaveStartPos() {}

void RestoreSavedPos() {}
void SaveCameraTransform() {
this.savedPosition = this.camera.transform.position;
this.savedRotation = this.camera.transform.rotation;
this.savedFOV = this.camera.fov;
}

Camera camera;
void LoadCameraTransform() {
this.camera.transform.SetPositionAndRotation(this.savedPosition, this.savedRotation);
this.camera.fov = this.savedFOV;
}

// (...)

bool noclip = true;
Camera camera;

bool noclip = false;
float fovChange = 500f * Time.deltaTime;
float noclipSpeed = 50f;

const float noclipSpeed = 50f;
const float noclipFOV = 80f;

Vector3 savedPosition;
Quaternion savedRotation;
float savedFOV = 0f;
}
}
4 changes: 3 additions & 1 deletion src/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void Awake() {
}

void Update() {
if (Input.GetKeyDown(KeyCode.Quote)) {
if (Input.GetKeyDown(KeyCode.Numlock)) {
this.debug = !this.debug;
this.SetOn(this.debug);
}
Expand Down Expand Up @@ -83,6 +83,8 @@ void InGameShortcuts() {
}
}

// (...)

public KeyCode refillEnergyKey;
public KeyCode repositionKey;
public KeyCode switchCameraDistance;
Expand Down

0 comments on commit 5389834

Please sign in to comment.