The quick brown fox jumps over the lazy dog 904

The quick brown fox jumps over the lazy dog

Multiple raycasts with a non-infinite maxDistance.

Basically do a raycast x units forward. Make new ray starting at that end position, move ray direction down some amount, raycast x units forward. Repeat.

The quick brown fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog

Couldn’t you move the ray a few degrees randomly? I would generate a random int, then add it to one of the axis rotations (X or Y) so that it would point slightly differently. Or you could also have real bullet effects by instantiating a bullet that would do the randomization with its own script.

The quick brown fox jumps over the lazy dog

Took it on myself as a challenge, as I’ll need this in the future too:

using UnityEngine;
using System.Collections;
using System.Linq;

public class TESTScript : MonoBehaviour {

    //how much we move
    public float RandomAmount;
    //min-max range of how much we want to move
    public float RandomRange = 0.01f;
    // self-explanatory name
    public Vector3 NewRotation;
    // Use this for initialization
    void Start ()
    {
        RandomAmount = Random.Range(RandomRange * -1, RandomRange);
    }
   
    // Update is called once per frame
    void FixedUpdate ()
    {
        //create random amount
        RandomAmount = Random.Range(RandomRange * -1, RandomRange);
        //randomize Z and Y
        float NewZ = RandomAmount += transform.eulerAngles.z;
        RandomAmount = Random.Range(RandomRange * -1, RandomRange);
        float NewY = RandomAmount += transform.eulerAngles.y;
        //rotate
        NewRotation = new Vector3(transform.rotation.x, NewY, NewZ);
        //shoot it
        ShootRay();
        //see in editor
        Debug.DrawRay(transform.position, NewRotation * 100, Color.red);
    }

    void ShootRay()
    {
        Ray ray = new Ray(this.transform.position, NewRotation);
    }
}

Should simulate an assault-rifle-style dispersion.

The quick brown fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog

Glad to see it worked for you, the exact execution isn’t as important as the result. I’m glad you could find parts of my script that helped you make the ultimate solution for your project :slight_smile:

1 Like

The quick brown fox jumps over the lazy dog

1 Like

Yup, that shows just how much of a noob I am at scripting :confused: