-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraFollow.cs
38 lines (28 loc) · 1006 Bytes
/
CameraFollow.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
using Godot;
using System;
public partial class CameraFollow : Camera3D
{
[Export]
public Player Target;
private double _mass, _stiffness, _damping, _maxSpeed;
[Export(PropertyHint.Range, "0.0, 250")]
public double MaxSpeed;
[Export(PropertyHint.Range, "0.0, 150")]
public double Mass;
[Export(PropertyHint.Range, "0.0, 25")]
public double Stiffness;
[Export(PropertyHint.Range, "0.0, 250")]
public double Damping;
[Export(PropertyHint.Range, "0.0, 150")]
public double Height = 30;
private Vector3 velocity;
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _PhysicsProcess(double delta)
{
if(Target == null) return;
var TargetPosition = Target.TargetPosition;
TargetPosition.Y = Height;
velocity += OG.Spring.GetForce(Mass, Stiffness, Damping, GlobalPosition, TargetPosition, delta, velocity) * MaxSpeed;
GlobalPosition += velocity;
}
}