<commit_before>﻿using UnityEngine;

public class RunnerController : MonoBehaviour
{
	[SerializeField] private float maxSpeed = 10f; 
	[SerializeField] private float jumpForce = 400f; 
	[SerializeField] private float addedJumpForce = 80f;
	[SerializeField] private LayerMask whatIsGround; //A mask determining what is ground to the runner

	private Transform groundCheck; 
	private float groundedHeightTest = 4f; 
	private bool grounded = false; 
	private bool jumping = false;

	public float minTimeBetweenJumps = 0.25f;
	public float maxJumpExtendTime = 1f;

	private float timeSinceLastJump = 0.0f;
	private float timeExtendingJump = 0.0f;
	private bool canExtendJump = false;

	private void Awake()
	{
	    groundCheck = transform.Find("GroundCheck");
		timeSinceLastJump = minTimeBetweenJumps + 1f;
	}

	private void FixedUpdate()
	{
		grounded = Physics2D.OverlapArea(new Vector2(groundCheck.position.x - 16, groundCheck.position.y),
		                                 new Vector2(groundCheck.position.x + 16, groundCheck.position.y - groundedHeightTest),
		                                 whatIsGround);

		timeSinceLastJump += Time.deltaTime;
	}


	public void Move(float move, bool jumpPressed, bool jumpExtending)
	{
		bool canJump = false; 

		rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);

		if (timeSinceLastJump > minTimeBetweenJumps && grounded) {
			jumping = false;
			canJump = true;
		}

		//First check if we are able to jump or not.
	    if (canJump && jumpPressed) {
	        grounded = false;
	        rigidbody2D.AddForce(new Vector2(0f, jumpForce));
			timeSinceLastJump = 0f;
			timeExtendingJump = 0f;
			canExtendJump = true;
			jumping = true;

			return; //We're done here
	    }

		//If we are currently jumping we might be able to extend the jump if the jump button is still pressed!
		//The following criteria have to be satisfied: 
		// (1) We are currently jumping.
		// (2) The jump button is pressed
		// (3) We can extend the jump (the moment the jump button is let go of we can no longer extend the current jump)
		// (4) We have not been extending the jump for too long
		// (5) We are not moving downwards (more of a sanity check than anything)
		if (jumping && jumpExtending && canExtendJump && 
		    timeExtendingJump < maxJumpExtendTime && rigidbody2D.velocity.y > 0f) {
			timeExtendingJump += Time.deltaTime;
			var normalizedJumpForce = addedJumpForce * Mathf.Lerp(1, 0, timeExtendingJump / maxJumpExtendTime);
			rigidbody2D.AddForce(new Vector2(0f, normalizedJumpForce));
		} else { //We're not extending the jump, so block it from happening for the rest of this jump.
			canExtendJump = false;
		}
	}
}
<commit_msg>Reducing vertical velocity if hitting a wall while jumping<commit_after>﻿using UnityEngine;

public class RunnerController : MonoBehaviour
{
	[SerializeField] private float maxSpeed = 10f; 
	[SerializeField] private float jumpForce = 400f; 
	[SerializeField] private float addedJumpForce = 80f;
	[SerializeField] private LayerMask whatIsGround; //A mask determining what is ground to the runner

	private Transform groundCheck; 
	private float groundedHeightTest = 4f; 
	private bool grounded = false; 
	private bool jumping = false;

	public float minTimeBetweenJumps = 0.25f;
	public float maxJumpExtendTime = 1f;

	private float timeSinceLastJump = 0.0f;
	private float timeExtendingJump = 0.0f;
	private bool canExtendJump = false;

	private bool hitWall = false;

	private void Awake()
	{
	    groundCheck = transform.Find("GroundCheck");
		timeSinceLastJump = minTimeBetweenJumps + 1f;
	}

	private void FixedUpdate()
	{
		grounded = Physics2D.OverlapArea(new Vector2(groundCheck.position.x - 16, groundCheck.position.y),
		                                 new Vector2(groundCheck.position.x + 16, groundCheck.position.y - groundedHeightTest),
		                                 whatIsGround);

		timeSinceLastJump += Time.deltaTime;

		//If we're jumping and hit a wall, reduce vertical velocity enough that we can 
		//still *potentially* make it over the wall if we were close enough. Otherwise we'll just fall.
		if (jumping && rigidbody2D.velocity.x < 0.001f && rigidbody2D.velocity.x >= 0) {
			canExtendJump = false;
			rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y * 0.25f);
		}
	}


	public void Move(float move, bool jumpPressed, bool jumpExtending)
	{

		bool canJump = false; 

		rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);

		if (timeSinceLastJump > minTimeBetweenJumps && grounded) {
			jumping = false;
			canJump = true;
		}

		//First check if we are able to jump or not.
	    if (canJump && jumpPressed) {
	        grounded = false;
	        rigidbody2D.AddForce(new Vector2(0f, jumpForce));
			timeSinceLastJump = 0f;
			timeExtendingJump = 0f;
			canExtendJump = true;
			jumping = true;

			return; //We're done here
	    }

		//If we are currently jumping we might be able to extend the jump if the jump button is still pressed!
		//The following criteria have to be satisfied: 
		// (1) We are currently jumping.
		// (2) The jump button is pressed
		// (3) We can extend the jump (the moment the jump button is let go of we can no longer extend the current jump)
		// (4) We have not been extending the jump for too long
		// (5) We are not moving downwards (more of a sanity check than anything)
		if (jumping && jumpExtending && canExtendJump && 
		    timeExtendingJump < maxJumpExtendTime && rigidbody2D.velocity.y > 0f) {
			timeExtendingJump += Time.deltaTime;
			var normalizedJumpForce = addedJumpForce * Mathf.Lerp(1, 0, timeExtendingJump / maxJumpExtendTime);
			rigidbody2D.AddForce(new Vector2(0f, normalizedJumpForce));
		} else { //We're not extending the jump, so block it from happening for the rest of this jump.
			canExtendJump = false;
		}
	}
}

{'fraction_non_alphanumeric': 0.08407534246575342, 'fraction_numerical': 0.017465753424657535, 'mean_word_length': 3.4317147192716235, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7140067', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1796, 'n_words': 597}