72 lines
1.2 KiB
C#
72 lines
1.2 KiB
C#
using Godot;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Godot.Collections;
|
|
|
|
namespace Rokojori
|
|
{
|
|
[GlobalClass]
|
|
public partial class Jump:CharacterControllerAction
|
|
{
|
|
[Export]
|
|
public RJSensor button;
|
|
|
|
[Export]
|
|
public float jumpStrength;
|
|
|
|
[Export]
|
|
public float maxJumpDuration;
|
|
|
|
[Export]
|
|
public Curve jumpCurveStrength = MathX.Curve( 1, 0 );
|
|
|
|
[Export]
|
|
public float jumpedDuration;
|
|
|
|
[Export]
|
|
public bool canJump = false;
|
|
|
|
[Export]
|
|
public bool jumping = false;
|
|
|
|
|
|
|
|
public override void _OnTrigger()
|
|
{
|
|
if ( body.IsOnFloor() )
|
|
{
|
|
jumping = false;
|
|
}
|
|
|
|
if ( ! ( jumping || body.IsOnFloor() ) )
|
|
{
|
|
return;
|
|
}
|
|
|
|
if ( ! button.IsActive() )
|
|
{
|
|
jumping = false;
|
|
return;
|
|
}
|
|
|
|
if ( ! jumping )
|
|
{
|
|
jumping = true;
|
|
jumpedDuration = 0;
|
|
}
|
|
|
|
jumpedDuration += controller.delta;
|
|
|
|
canJump = jumpedDuration < maxJumpDuration;
|
|
|
|
|
|
if ( jumpedDuration < maxJumpDuration )
|
|
{
|
|
var jumpStrengthMultiply = jumpCurveStrength.Sample( jumpedDuration / maxJumpDuration );
|
|
AddVelocity( Vector3.Up * jumpStrength );
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
} |