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);
}
}
}