-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreeCam.cs
More file actions
77 lines (59 loc) · 1.71 KB
/
FreeCam.cs
File metadata and controls
77 lines (59 loc) · 1.71 KB
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
using Godot;
namespace Destruct3D;
public partial class FreeCam : Camera3D
{
// if true, this script will deactivate all collisions for the player after the first use of the freecam
[Export] private bool PlayerDebugMode = false;
[Export] private float Speed = 15.0f;
[Export] private float SPRINT_FACTOR = 5.0f;
private bool Sprinting = false;
//should prolly be the same as the player's main camera sensitivity
private const float CameraSensitivity = 0.005f;
public override void _Ready()
{
base._Ready();
}
public override void _Process(double delta)
{
base._Process(delta);
if (Current)
{
Vector2 inputVector = new(Input.GetAxis("left", "right"), Input.GetAxis("backward", "forward"));
Position += Basis * new Vector3(inputVector.X * Speed * (float)delta, 0, -inputVector.Y * Speed * (float)delta);
}
}
public override void _UnhandledInput(InputEvent @event)
{
if (!Current) { return; }
base._UnhandledInput(@event);
if (@event is InputEventMouseButton mouseButtonEvent)
{
if (mouseButtonEvent.ButtonIndex == MouseButton.Left)
{
Input.SetMouseMode(Input.MouseModeEnum.Captured);
}
}
else if (Input.IsActionPressed("ui_cancel"))
{
Input.SetMouseMode(Input.MouseModeEnum.Visible);
}
if (Input.GetMouseMode() == Input.MouseModeEnum.Captured &&
@event is InputEventMouseMotion mouseMotionEvent)
{
GlobalRotate(Vector3.Up, -mouseMotionEvent.Relative.X * CameraSensitivity);
RotateObjectLocal(new Vector3(1, 0, 0), -mouseMotionEvent.Relative.Y * CameraSensitivity);
}
if (Input.IsActionJustPressed("sprint_toggle"))
{
if (Sprinting)
{
Speed /= SPRINT_FACTOR;
}
else
{
Speed *= SPRINT_FACTOR;
}
Sprinting = !Sprinting;
}
}
}