- Home /
Player not responding to Jump Input
(I'm really new at Unity! Please be forgiving!) I'm working on a tutorial series where I have the Character Controller scripted to do some basic movement with the arrow keys and WASD with the spacebar set to make the player jump. Everything works except the jump. Not really sure how to fix this. Any ideas? Here's my code:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
CharacterController _controller;
[SerializeField]
float _moveSpeed = 5.0f;
[SerializeField]
float _jumpSpeed = 20.0f;
[SerializeField]
float _gravity = 1.0f;
float _yVelocity = 0.0f;
// Use this for initialization
void Start ()
{
_controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update ()
{
Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
Vector3 velocity = direction * _moveSpeed;
if (_controller.isGrounded)
{
if (Input.GetButtonDown("jump"))
{
_yVelocity = _jumpSpeed;
}
}
else
{
_yVelocity -= _gravity;
}
velocity.y = _yVelocity;
_controller.Move(direction * Time.deltaTime);
}
}
I don't know if this will work. its just a guess but try capitalizing your string jump. ID$$anonymous$$ if I am right or wrong.
What things have you tried to make this work? When you say the jump doesn't work, what happens.
@Graham Dunnett: I've tried a few things. I tried to change the placement of the model in the scene. $$anonymous$$oving it farther down to the ground only resulted in the character controller moving up to the top of the ground with a key press from the arrow keys or WASD with the spacebar still not working. I tried to change the move and jump speed values in the code and in the inspector with no success. Not really sure what else to change.
Answer by Vonni · Apr 11, 2013 at 03:11 PM
This is something you need to get used to
A good technique is to add
// Add inside Input.Getbutton brackets
Debug.Log("My jump velocity when I jump is: " + _jumpSpeed);
Doing checks like this along the code will help you find where something is going wrong.
Also check if your _jumpSpeed variable in the inspector is 0 or something. Values in the inspector(unity editor) thrump any values inside the code.
Thanks for the help Vonni! I tried to debug and I got the value I put in for the jump speed but the character controller still isn't responding. I'm actually getting a new error now. It says this:
UnityException: Input Button jump is not setup. To change the input settings use: Edit -> Project Settings -> Input Player$$anonymous$$ovement.Update () (at Assets/TheGame/Scripts/Player$$anonymous$$ovement.cs:34)
I followed the tutorial for what it wanted code wise but I'm not sure what to change. Tried to change the input name in the Project Settings but it didn't work. Any ideas?
if (Input.GetButtonDown("jump"))
Change to:
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
Unfortunately there was no change. Should I just delete the character controller and try again with a new game object? I have a feeling it won't do any good since I'm going to use the same code and get right back to where I started.
Yeah I had a feeling I would have to start again. Here's hoping it works the second time around. Thanks for your help though! I really appreciate it! :)
Your answer
Follow this Question
Related Questions
Character Controller doesn't always follow it's parent position? 0 Answers
Strange Character Controller Behavior Caused by Simulated Gravity and Ground Check 0 Answers
,How to fix Crouch and Sprint Code (C#) 0 Answers
Character Creeping Backwards 0 Answers
Character Controller "walking on air" off cliffs/slopes 1 Answer