Hi!
I am trying to create some kind of FPS minigame and I need my bullets to hit something, obviously. But they only hit like 20% of the time. But if I stand right in front of my target they hit 95% of the time. I am using a raycast to register if it hits anything. Here’s my script.
rigidbody.AddRelativeForce(Vector3.up * speed * 100 * Time.deltaTime);
if(Physics.Raycast(transform.position, transform.up, out hit, 0.2f, enemyLayer) && expended == false){
expended = true;
trail.enabled = false;
Debug.Log ("Hit enemy");
if(hit.transform.gameObject.tag == "Head"){
Instantiate(bloodHeavy, hit.point, Quaternion.identity);
}
if(hit.transform.gameObject.tag == "Arm" || hit.transform.gameObject.tag == "Leg"){
Instantiate(bloodLight, hit.point, Quaternion.identity);
}
if(hit.transform.gameObject.tag == "Body"){
Instantiate(bloodMedium, hit.point, Quaternion.identity);
}
}
The code is located in Update().
If you know why they don’t hit anything, please tell me!
Thanks