I’m trying to implement jumping into the Roll-A-Ball tutorial. I’ve wrote something that seems to work most of the time, but sometimes it fails to respond. In particular, going north-west with the ball would not allow the ball to jump.
Here’s the code I’ve wrote:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float accelConstant;
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
float jumpers = 0;
if(Input.GetKeyDown (KeyCode.Space))
{
jumpers = 20.0f;
}
Vector3 movement = new Vector3 (moveHorizontal, jumpers, moveVertical);
rigidbody.AddForce (movement * accelConstant * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive (false);
}
}
}