Skip to content

Instantly share code, notes, and snippets.

@bzgeb
Created August 5, 2021 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bzgeb/cc31200da65d6927aa02f5e626249fda to your computer and use it in GitHub Desktop.
Save bzgeb/cc31200da65d6927aa02f5e626249fda to your computer and use it in GitHub Desktop.
Starter Assets Jump Test
using System.Collections;
using UnityEngine;
namespace StarterAssets.Test
{
public class JumpTest : MonoBehaviour
{
[SerializeField] StarterAssetsInputs _input;
[SerializeField] float _runTime = 0.1667f;
[SerializeField] float _time = 1.1667f;
[SerializeField] bool _sprint;
float _startingHeight;
Vector3 _startingPosition;
public float JumpHeight;
public float JumpDistance;
IEnumerator Start()
{
_input.sprint = _sprint;
float elapsed = 0;
_input.move = new Vector2(0f, 1f);
while (elapsed < _runTime)
{
yield return null;
elapsed += Time.deltaTime;
}
elapsed = 0f;
_input.jump = true;
_startingHeight = transform.position.y;
_startingPosition = transform.position;
while (elapsed < _time)
{
JumpHeight = Mathf.Max(transform.position.y - _startingHeight, JumpHeight);
yield return null;
elapsed += Time.deltaTime;
}
JumpDistance = (transform.position - _startingPosition).magnitude;
_input.move = new Vector2(0f, 0f);
Debug.Log($"Jump Height:{JumpHeight} Jump Distance:{JumpDistance}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment