mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:45:33 +00:00
42 lines
No EOL
927 B
C#
42 lines
No EOL
927 B
C#
using Godot;
|
|
|
|
namespace Cirno.Scripts.Actors._3D;
|
|
|
|
public partial class PropGravityModule3D : Node
|
|
{
|
|
[Export] public float FallingSpeed { get; private set; } = 10f;
|
|
|
|
private StaticBody3D _parent;
|
|
|
|
private bool _isFalling = false;
|
|
private int _detectedBodies = 0;
|
|
public override void _Ready()
|
|
{
|
|
_parent = GetParent<StaticBody3D>();
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
if (!_isFalling) return;
|
|
_parent.GlobalPosition += new Vector3(0, FallingSpeed , 0) * (float)delta;
|
|
}
|
|
|
|
public void OnBodyEntered(Node3D body)
|
|
{
|
|
if (body == _parent) return;
|
|
_detectedBodies++;
|
|
TryFalling();
|
|
}
|
|
|
|
public void OnBodyExited(Node3D body)
|
|
{
|
|
if (body == _parent) return;
|
|
_detectedBodies--;
|
|
TryFalling();
|
|
}
|
|
|
|
private void TryFalling()
|
|
{
|
|
_isFalling = _detectedBodies == 0;
|
|
}
|
|
} |