mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using GlitchyEngine;
|
|
using GlitchyEngine.Math;
|
|
|
|
using static GlitchyEngine.Math.Math;
|
|
|
|
namespace Sandbox;
|
|
public class Camera : Entity
|
|
{
|
|
public float DistanceFromPlayer = 5.0f;
|
|
|
|
public float DontFollowRadius = 3.0f;
|
|
|
|
void OnUpdate(float deltaTime)
|
|
{
|
|
Entity player = FindEntityWithName("Player");
|
|
|
|
if (player != null)
|
|
{
|
|
float2 playerPosition = player.Transform.Translation.XY;
|
|
|
|
float2 cameraPosition = Transform.Translation.XY;
|
|
|
|
float2 distanceVector = playerPosition - cameraPosition;
|
|
|
|
float distance = length(distanceVector);
|
|
|
|
float2 neededMovement = float2.Zero;
|
|
|
|
if (distance > DontFollowRadius)
|
|
{
|
|
neededMovement = distanceVector - (distanceVector / distance) * DontFollowRadius;
|
|
}
|
|
|
|
Transform.Translation = new float3(cameraPosition + neededMovement, DistanceFromPlayer);
|
|
}
|
|
else
|
|
{
|
|
Log.Error("Player not found!");
|
|
}
|
|
}
|
|
}
|