Basic pathfinding working for crying ghosts
This commit is contained in:
29
Abilities/Fireball/Fireballv3.cs
Normal file
29
Abilities/Fireball/Fireballv3.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user