Skip to content
Snippets Groups Projects
Commit ab87dc42 authored by Jeremy Gibson Bond's avatar Jeremy Gibson Bond
Browse files

Got the predictive line working and have integrated all GMTK jump values into...

Got the predictive line working and have integrated all GMTK jump values into better jump settings, however, characterJump still needs to be rewritten.
parent b69b2b82
No related branches found
No related tags found
No related merge requests found
using NaughtyAttributes;
using UnityEngine;
using UnityEngine.InputSystem;
......@@ -10,7 +11,8 @@
[RequireComponent(typeof(CharacterGround))]
public class CharacterJump : MonoBehaviour
{
[Header("Components")]
// [Header("Components")]
[InfoBox("If you want to see a prediction of the jump when this GameObject is selected, check showJumpLine in the Character_Settings_SO that you're using.", EInfoBoxType.Normal)]
[XnTools.Hidden] public Rigidbody2D rigid;
[XnTools.Hidden] public Vector2 velocity;
......@@ -33,7 +35,7 @@ public class CharacterJump : MonoBehaviour
// [SerializeField, Range(0, 1)][Tooltip("How many times can you jump in the air?")] public int maxAirJumps = 0;
// [Header("Options")]
// [Tooltip("Should the character drop when you let go of jump?")] public bool variablejumpHeight;
// [Tooltip("Should the character drop when you let go of jump?")] public bool variableJumpHeight;
// [SerializeField, Range(1f, 10f)][Tooltip("Gravity multiplier when you let go of jump")] public float jumpCutOff;
// [SerializeField][Tooltip("The fastest speed the character can fall")] public float speedLimit;
// [SerializeField, Range(0f, 0.3f)][Tooltip("How long should coyote time last?")] public float coyoteTime = 0.15f;
......@@ -82,7 +84,7 @@ public void OnJump(InputAction.CallbackContext context)
private void SetPhysics() {
//Determine the character's gravity scale, using the stats provided. Multiply it by a gravMultiplier, used later
Vector2 newGravity = new Vector2( 0, ( -2 * characterSettingsSO.jumpHeight ) / ( characterSettingsSO.timeToJumpApex * characterSettingsSO.timeToJumpApex ) );
Vector2 newGravity = new Vector2( 0, ( -2 * characterSettingsSO.jumpHeight ) / ( characterSettingsSO.jumpDuration.up * characterSettingsSO.jumpDuration.up ) );
rigid.gravityScale = ( newGravity.y / Physics2D.gravity.y ) * gravMultiplier;
}
......@@ -165,22 +167,20 @@ private void CalculateGravity()
else
{
//If we're using variable jump height...)
if ( characterSettingsSO.variablejumpHeight )
if ( characterSettingsSO.jumpSettingsVariableHeight.useVariableJumpHeight )
{
//Apply upward multiplier if player is rising and holding jump
if (pressingJump && currentlyJumping)
{
gravMultiplier = characterSettingsSO.upwardMovementMultiplier;
if (pressingJump && currentlyJumping) {
gravMultiplier = characterSettingsSO.jumpGrav.up;// characterSettingsSO.upwardMovementMultiplier;
}
//But apply a special downward multiplier if the player lets go of jump
else
{
gravMultiplier = characterSettingsSO.jumpCutOff;
else {
gravMultiplier = characterSettingsSO.jumpGrav.up * characterSettingsSO.jumpSettingsVariableHeight.gravUpMultiplierOnRelease;// characterSettingsSO.jumpCutOff;
}
}
else
{
gravMultiplier = characterSettingsSO.upwardMovementMultiplier;
gravMultiplier = characterSettingsSO.jumpGrav.up;// characterSettingsSO.upwardMovementMultiplier;
}
}
}
......@@ -197,7 +197,7 @@ private void CalculateGravity()
else
{
//Otherwise, apply the downward gravity multiplier as Kit comes back to Earth
gravMultiplier = characterSettingsSO.downwardMovementMultiplier;
gravMultiplier = characterSettingsSO.jumpGrav.down; //characterSettingsSO.downwardMovementMultiplier;
}
}
......@@ -233,8 +233,9 @@ private void DoAJump()
SetPhysics();
//If we have double jump on, allow us to jump again (but only once)
canJumpAgain = ( characterSettingsSO.maxAirJumps == 1 && canJumpAgain == false);
// canJumpAgain = ( characterSettingsSO.maxAirJumps == 1 && canJumpAgain == false);
canJumpAgain = ( characterSettingsSO.jumpsBetweenGrounding > 1 && canJumpAgain == false);
//Determine the power of the jump, based on our gravity and stats
jumpSpeed = Mathf.Sqrt(-2f * Physics2D.gravity.y * rigid.gravityScale * characterSettingsSO.jumpHeight );
if (jumpSpeed > 100) {
......@@ -308,22 +309,39 @@ private void OnSceneGUI() {
if ( !csso.showJumpLine ) return;
if ( csso.jumpSettingsType == Character_Settings_SO.eJumpSettingsType.GMTK_GameMakersToolKit ) return;
if (csso.jumpLinePoints == null) cMove.characterSettingsSO.CalculateJumpLine();
GUIStyle labelStyle = new GUIStyle( EditorStyles.foldoutHeader );
labelStyle.imagePosition = ImagePosition.TextOnly; // NOTE: This didn't seem to do anything.
labelStyle.richText = true;
Handles.matrix = Matrix4x4.Translate(cJump.transform.position); // Not needed because jump will be shown at origin.
Handles.matrix = Matrix4x4.Translate(cJump.transform.position);
Handles.color = Color.green;
Handles.DrawAAPolyLine(4, csso.jumpLinePoints);
Vector3 tVec;
Vector3[] jSME = csso.jumpStartMidEndPoints;
if ( jSME != null && jSME.Length == 3 ) {
Vector3 offset = Vector3.up * 0.2f;
Handles.DrawDottedLine( jSME[0] + offset, jSME[2] + offset, dashSize );
Vector3 tVec = ( jSME[0] + jSME[2] ) / 2f + offset * 4 + Vector3.left * 0.4f;
Handles.Label( tVec, $"Dist: {csso.maxJumpDistHeight.x:0.##}" );
tVec = ( jSME[0] + jSME[2] ) / 2f + offset * 4 + Vector3.left * 0.4f;
Handles.Label( tVec, $"<b>Dist: {csso.maxJumpDistHeight.x:0.##}</b>", labelStyle );
tVec = jSME[1];
tVec.y = 0;
Handles.DrawDottedLine( tVec, jSME[1], dashSize );
tVec = ( tVec + jSME[1] ) / 2f + Vector3.left * 0.4f;
Handles.Label( tVec, $"Height: {csso.maxJumpDistHeight.y:0.##}" );
Handles.Label( tVec, $"<b>Height: {csso.maxJumpDistHeight.y:0.##}</b>", labelStyle );
}
if ( csso.jumpSettingsVariableHeight.useVariableJumpHeight ) {
Handles.color = Color.magenta;
Handles.DrawAAPolyLine( 8, csso.minJumpLinePoints.ToArray() );
if ( csso.minJumpStartMidEndPoints != null &&
csso.minJumpStartMidEndPoints.Length == 3 ) {
tVec = csso.minJumpStartMidEndPoints[0] + Vector3.down * 0.25f;
Handles.Label( tVec, $"<b>Min: Ht: {csso.minJumpDistHeight.y:0.##} Dst: {csso.minJumpDistHeight.x:0.##}" +
$" tApex: {csso.minTimeApexFull.x:0.##} tFull: {csso.minTimeApexFull.y:0.##}</b>", labelStyle );
}
}
}
}
......
......@@ -25,9 +25,9 @@ public class InfoComponent : MonoBehaviour {
//[CanEditMultipleObjects]
public class InfoComponentEditor : Editor {
static private bool TURN_ON_DEFAULT_INSPECTORS = false;
static private bool DEBUG_GUI_ERRORS = false;
private const int delayGUIStart = 2;
private int delayGUI = 0;
private double failedGUITimeStamp = -1f;
//static float kSpace = 16f;
InfoComponent info;
......@@ -51,7 +51,6 @@ public class InfoComponentEditor : Editor {
void OnEnable() {
delayGUI = delayGUIStart;
info = (InfoComponent)target;
Init();
}
......@@ -67,13 +66,15 @@ static void EnableEdit(MenuCommand command) {
}
public override void OnInspectorGUI() {
if ( failedGUITimeStamp == EditorApplication.timeSinceStartup ) return;
if (info == null) {
info = (InfoComponent)target;
Init();
}
if ( !m_Initialized ) return;
if ( delayGUI > 0 ) {
delayGUI--;
if ( !m_Initialized ) {
failedGUITimeStamp = EditorApplication.timeSinceStartup;
if ( DEBUG_GUI_ERRORS )
Debug.LogWarning( $"InfoComponent Init() failed but it didn't cause an error message!)" ); //at {failedGUITimeStamp:#,0.###}.");
return;
}
......
......@@ -32,6 +32,16 @@ MonoBehaviour:
fullJumpDistanceMin: 0.5
fullJumpDistanceMax: 5.5
jumpApexFraction: 0.6
jumpSettingsVariableHeightCGSK:
useVariableJumpHeight: 1
upwardVelocityZeroing: 0
minJumpButtonHeldTime: 0.05
gravUpMultiplierOnRelease: 2.54
jumpSettingsVariableHeightGMTK:
useVariableJumpHeight: 1
upwardVelocityZeroing: 0
minJumpButtonHeldTime: 0.05
gravUpMultiplierOnRelease: 1
jumpDist:
up: 3.3000002
down: 2.1999998
......@@ -44,16 +54,18 @@ MonoBehaviour:
jumpGrav:
up: -22.22222
down: -50.000008
jumpDurationFromVideo: 5
timeToJumpApex: 0.6666666
upwardMovementMultiplier: 1
downwardMovementMultiplier: 1.4
maxAirJumps: 0
variablejumpHeight: 1
jumpCutOff: 2.5
maxJumpDistHeight: {x: 5.499999, y: 4}
minJumpDistHeight: {x: 3.0800004, y: 1.9994661}
jumpSettingsGMTK:
jumpDuration: 5
downGravity: 6.17
doubleJump: 0
variableJumpHeight: 0
jumpCutOff: 0
speedLimit: 26.45
coyoteTime: 0.15
jumpBuffer: 0.15
jumpsBetweenGrounding: 1
squashAndStretch: 0
jumpSquashSettings: {x: 0, y: 0, z: 0}
landSquashSettings: {x: 0, y: 0, z: 0}
......@@ -63,4 +75,3 @@ MonoBehaviour:
leanForward: 0
maxTilt: 0
tiltSpeed: 0
maxJumpDistHeight: {x: 5.499999, y: 4}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment