Character controls, camera with dead zone, flashlight scale
This commit is contained in:
parent
f307a7ef00
commit
bbc3f0821e
7 changed files with 80 additions and 4 deletions
|
@ -2,11 +2,41 @@ using Godot;
|
|||
|
||||
public partial class GameCamera : Camera2D
|
||||
{
|
||||
[Export] public Player Player;
|
||||
[Export] public Vector2 CameraBounds;
|
||||
|
||||
/// <summary>
|
||||
/// World position of the flashlight
|
||||
/// </summary>
|
||||
public Vector2 FlashlightPosition;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var relativePlayerPosition = Player.Position - Position;
|
||||
var halfCameraBounds = CameraBounds / 2;
|
||||
float x = 0, y = 0;
|
||||
if (relativePlayerPosition.X > halfCameraBounds.X)
|
||||
{
|
||||
x = relativePlayerPosition.X - halfCameraBounds.X;
|
||||
}
|
||||
else if (relativePlayerPosition.X < -halfCameraBounds.X)
|
||||
{
|
||||
x = relativePlayerPosition.X + halfCameraBounds.X;
|
||||
}
|
||||
if (relativePlayerPosition.Y > halfCameraBounds.Y)
|
||||
{
|
||||
y = relativePlayerPosition.Y - halfCameraBounds.Y;
|
||||
}
|
||||
else if (relativePlayerPosition.Y < -halfCameraBounds.Y)
|
||||
{
|
||||
y = relativePlayerPosition.Y + halfCameraBounds.Y;
|
||||
}
|
||||
|
||||
var difference = new Vector2(x, y);
|
||||
Position += difference;
|
||||
FlashlightPosition += difference;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
base._Input(@event);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue