40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using Godot;
|
|
using static GameData;
|
|
|
|
public partial class Camera3d : Camera3D
|
|
{
|
|
[Export] public float Speed = 7.5f;
|
|
[Export] public float MouseSensitivity = 0.2f;
|
|
[Export] public float ScrollStrength = 5.0f;
|
|
|
|
private Vector2 _mouseDelta;
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
float d = (float)delta;
|
|
|
|
var rotation = RotationDegrees;
|
|
rotation.X = Mathf.Clamp(rotation.X, -90f, 90f);
|
|
RotationDegrees = rotation;
|
|
|
|
_mouseDelta = Vector2.Zero;
|
|
|
|
Vector3 direction = Vector3.Zero;
|
|
if (Input.IsActionPressed("move_forward") && Position.Z > 0) direction += Transform.Basis.Z;
|
|
if (Input.IsActionPressed("move_backward") && Position.Z < layerSize * 4) direction -= Transform.Basis.Z;
|
|
if (Input.IsActionPressed("move_left") && Position.X > 0) direction -= Transform.Basis.X;
|
|
if (Input.IsActionPressed("move_right") && Position.X < layerSize * 4) direction += Transform.Basis.X;
|
|
|
|
if (direction != Vector3.Zero)
|
|
{
|
|
direction = direction.Normalized() * Speed * (Input.IsActionPressed("sprint") ? 2.5f : 1) * d;
|
|
Translate(direction);
|
|
}
|
|
|
|
if (Position.Y != 10 - visibleLayer * 4)
|
|
{
|
|
Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z);
|
|
}
|
|
}
|
|
}
|