- Home /
Movement Jumping Help
Hi!
I'm creating a 2D sidescroller. Right now I'm trying to create a movement script however I'm having a little trouble with the jumping. I've got my character to jump up however right now the character just aims for the ground and misses. (floats) Does anyone know how I can monitor how high the character can jump while not hamping movement (like found in CharacterController). I've posted the code bellow.
Thanks!
Code (written in C#)
void Update () {
float speed = 20.0F;
float jumpSpeed = 13.0F;
//Here is where I will monitor key presses for player movement
float translation = Input.GetAxis("Horizontal") * speed;
float jumping = Input.GetAxis("Jump") * jumpSpeed;
translation *= Time.deltaTime;
jumping *= Time.deltaTime;
transform.Translate(translation, 0,jumping);
}
What does "... the character just aims for the ground and misses. (floats)" mean? Also, what is Input.GetAxis("Jump")? Is "Jump" your vertical axis?
When I let go of the space bar the character does not fall but stays on the say vertical level. With Jump that is my vertical axis and corresponds when I press the space bar.
First of I'd say try changing Input.GetAxis("Jump")
to Input.GetButtonDown("Jump")
.
And second you have no if statements in your code so the code doesn't know what logic to run and what to do. Create logic that can be executed for jumping and movement. Something like:
if(Input.GetButtonDown("Jump"))
{
//The jumping logic goes here.
}
If that isn't going well then I'd say try looking at a 2d runner tutorial for c#. Here is the link for it. http://catlikecoding.com/unity/tutorials/runner/
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
My character moves when i dont want to 0 Answers
How do i maintain the same speed in the air? 1 Answer
Player Jumps instead of moving forward 0 Answers
Character floats down after jumping 0 Answers