- Home /
Question by
ArchMag1cs42 · Sep 07, 2018 at 02:22 AM ·
jumpingnot workingforce
Jumping doesn't work, and I don't know why.
This jump function does not work, and I don't know why. Doesn't do anything when I hit space. Can Anyone Debug it?
using UnityEngine;
[RequireComponent(typeof(playerMotor))] public class playerController : MonoBehaviour {
[SerializeField]
private float speed = 5f;
[SerializeField]
private float lookSpeed = 3f;
[SerializeField]
public Vector3 jump = Vector3.up;
public float jumpForce = 3.0f;
private Rigidbody rb;
private playerMotor motor;
void Start()
{
rb = GetComponent<Rigidbody>();
motor = GetComponent<playerMotor>();
}
void Update()
{
float _xMov = Input.GetAxisRaw("Horizontal");
float _zMov = Input.GetAxisRaw("Vertical");
Vector3 _movHorizontal = transform.right * _xMov;
Vector3 _movVertical = transform.forward * _zMov;
Vector3 _velocity = (_movHorizontal + _movVertical).normalized * speed;
motor.Move(_velocity);
float _yRot = Input.GetAxisRaw("Mouse X");
Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSpeed;
motor.Rotate(_rotation);
float _xRot = Input.GetAxisRaw("Mouse Y");
float _camRotationX = _xRot * lookSpeed;
motor.RotateCamera(_camRotationX);
if(Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
}
}
}
Comment
Best Answer
Answer by cj-carey · Sep 07, 2018 at 03:29 AM
I think that your jumpforce might be just too small. 3.0f is really little. Try bumping it up to something like 300f.