how do I make my character jump while running without losing all your speed
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);
}
}
Answer by rmolenkamp · Jul 08, 2016 at 08:36 AM
Why aren't you using the transform.Translate for your jump? I think that may solve your problem. Also, wouldn't movement teleport the character right back to the floor since you're writing transform.Translate(x, 0, z)? That could be an additional issue.
Your answer
Follow this Question
Related Questions
Why doesn't the collider work? 1 Answer
jump code character can jump twice please any one fix this 0 Answers
C# Code won't ket me jump 0 Answers
Jump Using Raycast. 0 Answers