-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFreecam.cs
99 lines (77 loc) · 3.58 KB
/
Freecam.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using BrokeProtocol.Utility;
using BrokeProtocolClient.settings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BrokeProtocolClient.modules.render
{
class Freecam : Module
{
public NumberSetting speed = new NumberSetting("Speed", 1, 1000, 180, 1);
public NumberSetting speedBoost = new NumberSetting("Speed boost multiplier", 1, 10, 5, 0.5);
Transform originalCameraParent = null;
CameraMode originalCameraMode = CameraMode.FirstPerson;
bool shouldFreecam;
public Freecam() : base(Categories.Render, "Freecam", "Allows to move camera away from the player")
{
addSetting(speed);
addSetting(speedBoost);
}
public override void onActivate()
{
if (!getClient().ClManager.myPlayer) return;
if (!getClient().MainCamera) return;
originalCameraParent = getClient().ClManager.myPlayer.originT;
originalCameraMode = getClient().MainCamera.cameraMode;
shouldFreecam = true;
getClient().MainCamera.worldCameraT.SetParent(null);
getClient().MainCamera.cameraMode = CameraMode.FirstPerson;
}
public override void onDeactivate()
{
if (!getClient().ClManager.myPlayer) return;
if (!getClient().MainCamera) return;
shouldFreecam = false;
getClient().MainCamera.worldCameraT.SetParent(originalCameraParent);
getClient().MainCamera.worldCameraT.localPosition = Vector3.zero;
getClient().MainCamera.worldCameraT.localRotation = Quaternion.identity;
}
public override void onRender()
{
}
public override void onUpdate()
{
if (!getClient().ClManager.myPlayer) return;
if (!getClient().MainCamera) return;
getClient().MainCamera.cameraMode = CameraMode.FirstPerson;
var player = getClient().ClManager.myPlayer;
Vector3 vector = Vector3.zero;
if (Keyboard.current.wKey.isPressed)
vector += new Vector3(getClient().MainCamera.worldCamera.transform.forward.x, 0, getClient().MainCamera.worldCamera.transform.forward.z).normalized;
if (Keyboard.current.sKey.isPressed)
vector -= new Vector3(getClient().MainCamera.worldCamera.transform.forward.x, 0, getClient().MainCamera.worldCamera.transform.forward.z).normalized;
if (Keyboard.current.aKey.isPressed)
vector -= getClient().MainCamera.worldCamera.transform.right;
if (Keyboard.current.dKey.isPressed)
vector += getClient().MainCamera.worldCamera.transform.right;
if (Keyboard.current.spaceKey.isPressed)
vector += Vector3.up;
if (Keyboard.current.ctrlKey.isPressed)
vector += Vector3.down;
var boost = 1f;
if (Keyboard.current.shiftKey.isPressed)
boost = speedBoost.getValueFloat();
getClient().MainCamera.worldCameraT.position += vector * speed.getValueFloat() * boost * Time.deltaTime;
getClient().MainCamera.worldCameraT.rotation = getClient().ClManager.myPlayer.GetRotation;
getClient().ClManager.myPlayer.ZeroInputs();
}
public bool ShouldFreecam()
{
return !shouldFreecam;
}
}
}