35 lines
954 B
C#
35 lines
954 B
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class Fireballv2 : ProjectileBase
|
|
{
|
|
[Export] public float TurnRate { get; set; }
|
|
[Export] public float OrbitStrength { get; set; }
|
|
|
|
Vector2 _velocity;
|
|
|
|
public override void _Ready()
|
|
{
|
|
var direction = (GetGlobalMousePosition() - GlobalPosition).Normalized();
|
|
|
|
_velocity = direction * Speed;
|
|
Rotation = _velocity.Angle();
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
var targetDirection = (GetGlobalMousePosition() - GlobalPosition).Normalized();
|
|
var perp = targetDirection.Orthogonal();
|
|
|
|
targetDirection = (targetDirection + perp * OrbitStrength).Normalized();
|
|
var currentDirection = _velocity.Normalized();
|
|
var angle = currentDirection.AngleTo(targetDirection);
|
|
var maxTurn = TurnRate * (float)delta;
|
|
|
|
angle = Mathf.Clamp(angle, -maxTurn, maxTurn);
|
|
_velocity = _velocity.Rotated(angle);
|
|
GlobalPosition += _velocity * (float)delta;
|
|
Rotation = _velocity.Angle();
|
|
}
|
|
}
|