I made a script with character controller , but when the User button to jump button it jumps but misses full speed (do a parable ) he jumps straight and up only, anyone know what I can do for the player while running , jump and receive speed.
This is my script:
using UnityEngine;
using System.Collections;
public class PlayerBehaviour : MonoBehaviour {
//Speeds and Movimentation
public float speed;
public float walkSpeed = 6.0f;
public float turningSpeed = 100.0f;
public float runSpeed = 12.0f;
public float jumpSpeed = 8.0f;
//Phisics
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
//Booleans
//Animation
public Animator anim;
//Start
void Awake () {
anim = GetComponent<Animator> ();
}
void FixedUpdate () {
speed = walkSpeed;
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
float horizontal = Input.GetAxis ("Horizontal") * turningSpeed * Time.deltaTime;
transform.Rotate (0, horizontal, 0);
float vertical = Input.GetAxis ("Vertical") * speed * Time.deltaTime;
transform.Translate (0, 0, vertical);
//Run method
if(Input.GetKey("left shift")&& controller.isGrounded){
speed=runSpeed;
float v=Input.GetAxis ("Vertical") * speed * Time.deltaTime;
transform.Translate (0, 0, vertical);
}
}
if (Input.GetButton("Jump")&& controller.isGrounded){
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}