Player Jumping Issue
Hello all, this seems like a dumb question, but I am unable to find the issue with jumping. I have made a custom first-person controller for my game, and I cannot find a possible way to make the player jump. I've made sure that the object in the scene has a rigidbody. The code is below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player2Movement : MonoBehaviour {
public float speed = 5.0f;
public float jumpVelocity = 20.0f;
private Rigidbody rb;
void Start () {
}
void Update () {
float translation = Input.GetAxis("Vertical") * speed;
float strafe = Input.GetAxis("Horizontal") * speed;
translation *= Time.deltaTime;
strafe *= Time.deltaTime;
transform.Translate(strafe, 0, translation);
if (Input.GetButtonDown("Jump")) // <-- this if statement doesn't work.
{
rb.AddForce(0, jumpVelocity, 0);
}
}
}
Answer by tormentoarmagedoom · Feb 02, 2019 at 05:04 PM
Good day.
What button is Jump? I dont see this he key in my keyboard! Its a new kind of keyboard?
//Irony...
You need to say what button is. Its always the easiest way.
if (Input.GetKeyDown(KeyCode.Space))
or
if (Input.GetKeyDown(KeyCode.Tab))
or
if (Input.GetKeyDown(KeyCode.w))
Bye!
Your answer
![](https://koobas.hobune.stream/wayback/20220612190932im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Generate wind while moving 1 Answer
First Person Controller error, "IndexOutOfRangeException:Array index is out of range." 1 Answer
Why isn't this code dampining the x-axis of the player movement? 0 Answers
Unity's FPC apply camera deadzone for mouse 0 Answers
How to change rotation for a FirstPersonController through script. 0 Answers