rokojori_action_library/Runtime/Interactions/CharacterController/Gravity.cs

32 lines
761 B
C#
Raw Normal View History

2025-01-03 12:09:23 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
2025-05-21 20:44:28 +00:00
[Tool]
2025-05-27 06:51:48 +00:00
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/CCGravity.svg")]
2025-01-03 12:09:23 +00:00
public partial class Gravity:CharacterControllerAction
{
2025-12-21 18:56:48 +00:00
public static readonly float EarthGravity = 9.80665f;
[Export]
public GravityStrength strength;
2025-01-03 12:09:23 +00:00
[Export]
2025-12-21 18:56:48 +00:00
public GravityStrength fallingStrength;
2025-01-03 12:09:23 +00:00
2025-01-08 18:46:17 +00:00
protected override void _OnTrigger()
2025-01-03 12:09:23 +00:00
{
2025-12-21 18:56:48 +00:00
if ( isGrounded || strength == null )
2025-01-03 12:09:23 +00:00
{
return;
2025-12-21 18:56:48 +00:00
}
var strengthSource = body.Velocity.Y > 0 || fallingStrength == null ? strength : fallingStrength;
AddVelocity( Vector3.Down * strengthSource.GetGravityStrength( this ) );
2025-01-03 12:09:23 +00:00
}
}
}