Hello everyone
I am making a FPS prototype and it is going very well, but I can´t rap my brain around gun accuracy and showing a moving crosshair on a Guitext. My gun uses raycast to fire, but it is shooting in a strait line using transform.forward. I all ready looked at DastardlyBanana´s FPS package, but lets face it, it is just a little too complicated for me.
So can you give me some leads on how to make a spray effect using raycast, and a moving crosshair showing the guns accuracy on a Guitext?
Thank you.
Spread on a raycast is pretty simple. Just add a random factor to the x y and z of your direction vector before you pass it to the raycast. Something like this:
//declare a float value to control the spread factor. .02 is a good default
public var spreadFactor : float = 0.02;
then when you’re doing the raycast, instead of passing it transform.forward, store it in a variable before hand and add the spread.
var direction : Vector3 = transform.forward;
direction.x += Random.Range(-spreadFactor, spreadFactor);
direction.y += Random.Range(-spreadFactor, spreadFactor);
direction.z += Random.Range(-spreadFactor, spreadFactor);
if (Physics.Raycast (transform.position, direction, hit, distance)){
Hi can i ask for the C# part for this?