- Home /
Character won't move forward, only jump.
Just started with unity (and programming). I looked up some videos and tried to learn how to make a character move and jump. Everything works fine, but it seems when I move forward he just jumps. And moving backward does nothing. I checked the inputs in my settings and none of them were changed.
Here's the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ToasterMovement : MonoBehaviour
{
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
Answer by cgraf1 · Jun 02, 2017 at 06:00 PM
You have an Input.GetButton for jumping, but I don't see an Input for left or right.
Your answer
Follow this Question
Related Questions
UniRPG Error cs0121. 0 Answers
The raycasthit does not see the cillider when hitting it 2 Answers
Learn: Survival Shooter aim offset from mouse position 1 Answer
how to view 3d model fully controllable in unity 5 0 Answers
Why do placing a preprocessor directive inside another causes my script to lose proper indentation? 1 Answer