30 lines
751 B
C#
30 lines
751 B
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class Fireballv3 : ProjectileBase
|
|
{
|
|
[Export] public float TurnSpeed { get; set; }
|
|
|
|
Vector2 _velocity;
|
|
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
var direction = (GetGlobalMousePosition() - GlobalPosition).Normalized();
|
|
|
|
_velocity = direction * Speed;
|
|
Rotation = _velocity.Angle();
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
var targetDirection = (GetGlobalMousePosition() - GlobalPosition).Normalized();
|
|
var currentDirection = _velocity.Normalized();
|
|
var newDirection = currentDirection.Lerp(targetDirection, TurnSpeed * (float)delta).Normalized();
|
|
|
|
_velocity = newDirection * Speed;
|
|
GlobalPosition += _velocity * (float)delta;
|
|
Rotation = _velocity.Angle();
|
|
}
|
|
}
|