using Godot; using System; public partial class camera : Camera2D { [Export] public Vector2 OffsetAmount = new Vector2(100, 0); [Export] public float SmoothingSpeed = 0.1f; // Called when the node enters the scene tree for the first time. public CharacterBody2D Player; public override void _Ready() { Player = GetParent(); } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { Vector2 playerPos = Player.GlobalPosition; Vector2 playerV = Player.Velocity; Vector2 direction = playerV.Normalized(); Vector2 cameraTargetPos = playerPos + OffsetAmount * direction; GlobalPosition = GlobalPosition.Lerp(cameraTargetPos, SmoothingSpeed); } }