So, I’m creating some kind of shooter with raycasting shooting, but I have a very annoying problem with it.
Basically, my Raycast points at world center (0,0,0) instead of pointing in front of object.
Here’s my code:
public class shoot : MonoBehaviour
{
public Transform shootPoint;
private float timeOut = 0;
public float maxTime = 0.3f;
public RaycastHit hit;
public Transform bulHole;
void Update ()
{
if (Input.GetMouseButton(0)&& timeOut>maxTime)
{
FireOne();
}
timeOut += Time.deltaTime;
}
void FireOne()
{
Vector3 shoot = shootPoint.TransformDirection(Vector3.forward) * 10;
if (Physics.Raycast(shootPoint.position, shoot, out hit ,600))
{
print("boom");
Instantiate(bulHole, hit.transform.position, bulHole.rotation);
}
else
{
print("nope");
}
timeOut = 0;
}
}
I haven’t found answer to it anywhere on internet.
(I’m russian, so don’t mind if my English is worst thing you’ve ever seen in your life)