My bullet can not detect the collider and raycast can not detect the collision. It's very weird since the only way to get a message on the console is whenever I shoot bullets within the range of my terrain(either on or above), I instantly get "Terrain" printed on my console, but the raycast cannot detect any other objects and print anything, and if I go out of the range and shoot at a sphere, nothing gets printed. Everything in my game has a collider except the bullet.
Thanks!
void Update () {
if (Input.GetKey(KeyCode.KeypadEnter) && counter > delayTime)
{
Instantiate(bullet, transform.position, transform.rotation);
counter = 0;
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
{
Debug.Log(hit.collider.gameObject.name);
}
}
counter += Time.deltaTime;
}
Debug.DrawLine()
orDebug.DrawRay()
to figure out where the raycast is going - this may give you a better idea of where the issue lies (whether it's a failure to detect an object, or a misdirected ray). – SerliteInput.GetKey...
? If so, do you really want the num pad enter on held down ("auto fire")? Maybe giveif(Input.GetButtonDown("Jump") && counter > delayTime)
a try (that would be spacebar). – Gunnar B.