You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
674 B
23 lines
674 B
public partial class PushbackArea : Area3D |
|
{ |
|
[Export] public float PushForce { get; set; } = 24.0f; |
|
|
|
Player _player; |
|
float _radius; |
|
public override void _Ready() |
|
{ |
|
_player = GetParent<Player>(); |
|
_radius = ((CapsuleShape3D)GetNode<CollisionShape3D>("CollisionShape3D").Shape).Radius; |
|
} |
|
|
|
public override void _PhysicsProcess(double delta) |
|
{ |
|
foreach (var area in GetOverlappingAreas()) { |
|
var offset = (GlobalPosition - area.GlobalPosition) with { Y = 0 }; |
|
var directions = offset.Normalized(); |
|
var distance = offset.Length() / (_radius * 2); |
|
var force = (1 - distance) * PushForce * (float)delta; |
|
_player.Velocity += directions * force; |
|
} |
|
} |
|
}
|
|
|