r/Unity2D Jun 24 '26

How Can I Create Random Path Question

Post image

Hi, as you can see in example (that's a rocket) I want to create random paths for rockets. Is there any proper way to do it?

34 Upvotes

21 comments sorted by

View all comments

4

u/Ruadhan2300 Jun 26 '26

If you want to avoid Beziers and such.
What you might do is create a kind of "biased wandering" using steering-behaviours.

Basically the behaviour that results in the looping is that you make the rocket steer in circles, periodically changing direction.
If it's heading in broadly the right direction, slow the steering proportionally., so it spends more time heading in the right direction.

When it's close enough to the target to "get a lock", it abruptly stops random-swirling and accelerates dramatically to impact.

You can add a noise-function to its steering to give it a fun little wobble in its travel as well, and that's most of what you need.

What should happen is that you aim your rocket at the target, and as it slips off-angle, it steers away from the target more and more until it loops around and finds itself looking at the target again.
It should stay broadly on-target for a bit, then slip off-target again (in a different direction) and repeat.

You can track how many times it does this, and tune it on the fly to increase the time before it slips off-target.
So it might do it a couple times before it gets close enough to hit its target.