CameraView
Obenseuer is played in first person. The game also has a third person camera, but it is switched off in the normal game. CameraView asks the game to use it through the game’s own camera state. It never moves a camera by hand.
CameraView first and third person
Check IsAvailable first, because there is no camera on the main menu. Use SetThirdPerson, SetFirstPerson or Toggle to change the view, and IsFirstPerson to see which one is on.
public static class CameraView
{
public static bool IsAvailable { get; }
public static bool IsFirstPerson { get; }
public static bool ThirdPersonAllowed { get; }
public static bool SetThirdPerson(float distance = 2.5f);
public static void SetFirstPerson();
public static bool Toggle();
public static event Action<bool> ModeChanged;
}
| Method | Returns | What it does |
|---|---|---|
SetThirdPerson(distance) | bool | Switches to third person at this distance. Returns false when third person is not allowed. |
SetFirstPerson() | void | Switches back to first person. |
Toggle() | bool | Switches to the other view. Returns false when it is not available or refused. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | true when the game has a camera to control. false on the main menu. |
IsFirstPerson | bool | true when the view is first person. |
ThirdPersonAllowed | bool | false when third person cannot be used right now. See Things to know. |
| Event | Gives you | When it fires |
|---|---|---|
ModeChanged | bool | The view changes. true means it is now first person. |
Putting it together
Logs every change of view, and switches to third person once at start if the game allows it.
using BepInEx;
using BepInEx.Unity.Mono;
using ObenseuerCore;
public class ChaseCam : BaseUnityPlugin
{
private void Awake()
{
CameraView.ModeChanged += firstPerson => Logger.LogInfo(firstPerson ? "first person" : "third person");
}
private void Start()
{
if (CameraView.ThirdPersonAllowed) CameraView.SetThirdPerson(3f);
}
}
| Step | What it does |
|---|---|
CameraView.ModeChanged += ... | Logs each change of view. |
CameraView.ThirdPersonAllowed | Checks whether third person can be used right now. |
CameraView.SetThirdPerson(3f) | Switches to third person at a distance of 3. |
Things to know
- Nothing breaks on the main menu. With no camera, the properties return
false, and the methods returnfalseor do nothing. ThirdPersonAllowedisfalsewhen there is no camera, when a camera zone forces first person, or when an object has asked the game to turn off camera zoom. (The zone case is aPlayerCameraTriggerthat forces first person. The zoom case is a non-emptydisabledZoomList.)SetThirdPerson(distance)sets the camera distance and turns third person on. The game keeps the distance between its minimum and maximum. (It setscurrentDistanceclamped tominDistance..maxDistance. It clearsdisableThirdPersonandfirstpersonOnly, and keeps the vanilla values soTweaks.Cameracan put them back. The game’sFixedUpdatethen callsThirdPerson()on the next physics step.)- The view changes on the next physics step, not inside the call.
ModeChangedfires then, not whileSetThirdPersonruns. - A wall closer than about 0.6 metres keeps you in first person, because the game pulls the camera in when something is in the way. (The game’s collision sets
distancebelow 0.5.) SetFirstPersondoes not turn the view. The direction you are looking stays as it was, so the picture does not jump. (The controller’srotXandrotYstay as they are. It setscurrentDistance = 0and callsFirstPerson().)- A camera zone can force first person, and the framework follows it. A zone counts as forcing from the moment it asks for first person until it asks to stop, or until it is destroyed. (The framework watches
PlayerCameraTrigger.FirstPersonOnly(bool)with a postfix. A trigger counts from itsFirstPersonOnly(true)call until itsFirstPersonOnly(false)call, or until it is destroyed.) - The game’s own first-person lock does not count as a zone. The game sets that lock itself for the whole game. (
ThirdPersonCameraCollision.StartsetsfirstpersonOnlyfromdisableThirdPerson.) - The game saves the camera mode. A save made in third person stores the cleared lock flags, so loading it restores third person. (The game saves
firstperson,currentDistance,disableThirdPersonandfirstpersonOnly, the public fields withoutfsIgnorein the game’sSaveController.) - Use
CameraViewrather than the game’s camera methods, so held items stay right. The held-item code listens to the same view-change event, and the game’sFirstPerson()andThirdPerson()fire it. (PlayerHandItems.CameraModeChangeis subscribed to the same static event.)
Limits
- Vanilla 0.5.08 is first person only. Third person is a mode the game left dormant, so the player’s body, animations and clipping may look rough in it.
- A zone that is only switched off, without asking to stop, still counts. No game code uses these zones yet. How a zone is entered and left depends on the scene, and that has not been checked.
- If the framework cannot watch the camera zones, third person is refused instead of forced, and
ThirdPersonAllowedstaysfalse. (This is when the postfix onPlayerCameraTrigger.FirstPersonOnlycannot be installed.) - The first-person lock can come back when a new camera starts. A new
ThirdPersonCameraCollisionrunsStartagain, which sets the lock again. WhileThirdPersonToggleorAllowScrollZoomis on, the framework clears it again on the next frame. It has not been checked thatStartruns on every scene load.