Question by
zaper120 · May 07, 2016 at 05:04 AM ·
3djumpendless runner
How do I make my Character Jump?
Hello, so I am following this tutorial on youtube on creating an endless runner for my 3D unity game. The video is very informal however the maker did not include a way for the character to jump. So I am asking is, is there a way to add a jump feature to the script I already have so far?
using UnityEngine;
using System.Collections;
public class PlayerMotor : MonoBehaviour
{
private CharacterController controller;
private Vector3 moveVector;
private float speed = 5.0f;
private float verticalVelocity = 0.0f;
private float gravity = 12.0f;
private float animationDuration = 3.0f;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
if (Time.time < animationDuration)
{
controller.Move (Vector3.forward * speed * Time.deltaTime);
return;
}
moveVector = Vector3.zero;
if (controller.isGrounded)
{
verticalVelocity = -0.5f;
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
}
// X - Left and Right
moveVector.x = Input.GetAxisRaw ("Horizontal") * speed;
// Y - Up and Down
moveVector.y = verticalVelocity;
// Z - Forward and Backward
moveVector.z = speed;
controller.Move (moveVector * Time.deltaTime);
}
}
Comment
Answer by $$anonymous$$ · May 08, 2016 at 10:13 AM
Well look this video remember to convert 2d to 3d if you have any question feel free to ask https://www.youtube.com/watch?v=tEOZrHTpjTk∈dex=7&list=PL9dzgguwvkSmWJx3yanDKMr24GkHq7pjI rememeber to subscribe if you want