- Home /
Character constantly Bouncing issue
so im fairly new to scripting and working with unity in general. i have written a script for basic movement of my character, but when i press play in unity to test it out it bounces. i had it working just yesterday. anyways i want to make it so i push to jump not a constant jumping loop like it is i may have a setting or something on that im not familiar. anyways here is the script for it
using UnityEngine; using System.Collections;
public class movement : MonoBehaviour { //Variables 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>();
// is the controller on the ground?
if (controller.isGrounded) {
//Feed moveDirection with input.
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
//Multiply it by speed.
moveDirection *= speed;
//Jumping
if (Input.GetButton ("Jump"));
moveDirection.y = jumpSpeed;
}
//Applying gravity to the controller
moveDirection.y -= gravity * Time.deltaTime;
//Making the character move
controller.Move(moveDirection * Time.deltaTime);
Your answer
Follow this Question
Related Questions
Character Flying around uncontrollably 2 Answers
Enemy Character Controller 1 Answer
Mecanim and Child Objects 0 Answers
My Character Doesn't Move Properly 0 Answers
Bomberman like movement 1 Answer