I’m in the process of making a 2D game, not really a platformer but it’ll control like one. So, I have a script that lets my character move left and right, and sprint by pressing the shift key. (See it below)
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public float speed = 200f;//walk speed
public float sprint = 300f;//sprint speed
void Start()
{
}
void Update()
{
//sprint script
if ((Input.GetKey(KeyCode.LeftShift))&(Input.GetKey(KeyCode.D)))//right
{
transform.position += new Vector3(sprint * Time.deltaTime, 0.0f, 0.0f);
transform.localScale = new Vector3(-2, 2, 2);
}
if ((Input.GetKey(KeyCode.LeftShift)) & (Input.GetKey(KeyCode.A)))//left
{
transform.position -= new Vector3(sprint * Time.deltaTime, 0.0f, 0.0f);
transform.localScale = new Vector3(2, 2, 2);
}
//walk script
if (Input.GetKey(KeyCode.D))//right
{
transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 0.0f);
transform.localScale = new Vector3(-2, 2, 2);
}
if (Input.GetKey(KeyCode.A))//left
{
transform.position -= new Vector3(speed * Time.deltaTime, 0.0f, 0.0f);
transform.localScale = new Vector3(2, 2, 2);
}
}
}
So now all I need is a script that lets him jump up and down. He has a rigidbody and a box collider, if that matters. I’m not worried about animations yet, so just a simple jump script. But if possible, I’d want the script to work so that when he’s sprinting, he would jump farther than when he’s walking. I don’t know how much work that would take, so if I’d need to rewrite all my code to do it then don’t worry about it. But if possible, he jumps farther when he’s sprinting (holding down shift). If you could put it into the code above, I’d really appreciate it, but just the script by itself is fine.