mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Falling props
This commit is contained in:
parent
c0493c2008
commit
4728677e80
45 changed files with 171 additions and 540 deletions
42
Scripts/Actors/3D/PropGravityModule3D.cs
Normal file
42
Scripts/Actors/3D/PropGravityModule3D.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/3D/PropGravityModule3D.cs.uid
Normal file
1
Scripts/Actors/3D/PropGravityModule3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://hkmutmmjqh1e
|
||||
Loading…
Add table
Add a link
Reference in a new issue