Initial commit
This commit is contained in:
34
Abilities/Fireballv2.cs
Normal file
34
Abilities/Fireballv2.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user