Fast start and ending at jump but slow middle.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovePlayer : MonoBehaviour {
public KeyCode moveRight;
public KeyCode moveLeft;
public KeyCode jump;
public float playerSpeed = 0;
public float jumpHeight = 0;
public bool isAirBorn = false;
void Start () {
}
void Update () {
//X, Y, Z
GetComponent<Rigidbody>().velocity = new Vector3(playerSpeed, jumpHeight, 0);
if (Input.GetKey(moveRight)) {
playerSpeed = 7;
}
if (Input.GetKey(moveLeft)) {
playerSpeed = -7;
}
if ((Input.GetKeyUp(moveRight)) || (Input.GetKeyUp(moveLeft))) {
playerSpeed = 0;
}
if((Input.GetKey(jump)) && (isAirBorn == false)) {
//jumpHeight = 1 waitXSeconds jumpHeight = 2 WaitXSeconds jumpHeight = 3.... And so on until u get to 8 and then player starts falling.;
//Making a fast start and ending, and a slow middle.
isAirBorn = true;
StartCoroutine(stopJump());
}
}
void OnCollisionEnter(Collision other) {
if(other.gameObject.tag == "grounded") {
isAirBorn = false;
}
}
IEnumerator stopJump() {
yield return new WaitForSeconds(.35f);
jumpHeight = 0;
}
}
Comment
Your answer
Follow this Question
Related Questions
Can't jump when moving backwards and to the right or left (C#) 1 Answer
How to make the character walk-jump and walk (and resize the collider when crouched) ? 0 Answers
Anyone have any ideas on how I could improve my character jump to make it more realistic? 1 Answer
How can I make it so that the longer you hold down the jump button the higher the player jumps? 0 Answers
Issues Getting my GameObject to both Move Forward and Jump properly. 0 Answers