60 lines
1.6 KiB
C#
60 lines
1.6 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 Robot robot;
|
|
|
|
public override void _Ready()
|
|
{
|
|
Position = new Vector3(0, 0, tileWidth / 2);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
Control focused = GetViewport().GuiGetFocusOwner();
|
|
|
|
if (focused is LineEdit || focused is TextEdit) return;
|
|
if (canMove) MoveCamera(delta);
|
|
}
|
|
|
|
public void MoveCamera(double delta)
|
|
{
|
|
float d = (float)delta;
|
|
|
|
Vector3 rotation = RotationDegrees;
|
|
rotation.X = Mathf.Clamp(rotation.X, -90f, 90f);
|
|
RotationDegrees = rotation;
|
|
|
|
Vector3 direction = Vector3.Zero;
|
|
if (Input.IsActionPressed("move_forward") && Position.Z > 0) direction += Transform.Basis.Z;
|
|
if (Input.IsActionPressed("move_backward") && Position.Z < layerSize * 6) direction -= Transform.Basis.Z;
|
|
if (Input.IsActionPressed("move_left") && Position.X > 0) direction -= Transform.Basis.X;
|
|
if (Input.IsActionPressed("move_right") && Position.X < layerSize * 6) direction += Transform.Basis.X;
|
|
|
|
if (direction != Vector3.Zero)
|
|
{
|
|
robot = null;
|
|
direction = direction.Normalized() * Speed * (Input.IsActionPressed("sprint") ? 2.5f : 1) * d;
|
|
Translate(direction);
|
|
}
|
|
else if (robot != null)
|
|
{
|
|
Position = new Vector3(robot.Position.X, 10 - visibleLayer * 4, robot.Position.Z + 4f);
|
|
}
|
|
|
|
if (Position.Y != 10 - visibleLayer * 4)
|
|
{
|
|
Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z);
|
|
}
|
|
}
|
|
|
|
public void Follow(Robot robot)
|
|
{
|
|
this.robot = robot;
|
|
}
|
|
}
|