Ever since i added projectiles, my jump isn’t working at all. Sometimes the player “drifts” a little but there is no movement along the y axis at all. I’m really not sure how to fix it…
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public float jumpspeed;
public float gravity;
public float panspeed;
private Vector3 moveDirection;
//private Vector3 direction;
void Start () {
Screen.showCursor = false;
moveDirection = transform.forward;
}
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent < CharacterController >();
if (controller.isGrounded) {
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
if (Input.GetKeyDown ("space"))
moveDirection.y += jumpspeed;
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= speed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
transform.Rotate (0, Input.GetAxis ("Mouse X") * panspeed, 0);
}
}
Edit: the code for the projectile:
using UnityEngine;
using System.Collections;
public class Shooter : MonoBehaviour {
public Rigidbody projectile;
public Transform shotpos;
public float shootspeed = 10f;
public float shotforce = 1000f;
void Update () {
if (Input.GetMouseButtonUp(0)){
Rigidbody shooty = Instantiate (projectile, shotpos.position, shotpos.rotation) as Rigidbody;
Physics.IgnoreCollision(shooty.collider, collider);
shooty.AddForce(shotpos.forward * shotforce);
}
}
}
shotpos is the transform of the player