- Home /
This question was
closed Oct 01, 2018 at 07:21 AM by
hexagonius for the following reason:
Unity Answers is about help about Unity, not getting someone to write code for you.
Question by
dragondeltigre · Oct 01, 2018 at 06:18 AM ·
jumpingfixhorizontal movement
How can I make my character jump & move him by zone
Hi there. I have to make a runner as a final work for the university, and I was watching a runner tutorial, but the guy i'm watching never makes his character jump and move it buy zones (like Subway Surffers for example).
What should I change in my character Scrip?
public class PlayerMotor : MonoBehaviour { private CharacterController Controller; private Vector3 moveVector;
private float speed = 5.0f;
private float height = 3.0f;
private float verticalVelocity = 0.0f;
private float gravity = 15.0f;
private float animationDuration = 1.5f;
// 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.0f;
} else
{
verticalVelocity -= gravity * Time.deltaTime;
}
moveVector.x = Input.GetAxisRaw("Horizontal") * speed;
moveVector.y = verticalVelocity;
moveVector.z = speed;
Controller.Move(moveVector * Time.deltaTime);
}
}
Comment