Spytato
1
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);
}
}
}
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!