V
V
Void592021-11-08 19:26:44
C++ / C#
Void59, 2021-11-08 19:26:44

How to make chaotic movement in Unity?

Good day!
I need to create an enemy that will dangle headlong across the field, while he should not stupidly sharply change the vector, but turn around in an arc. It should move something like this: it assigns a point on the field, flies there, when it flies it assigns a new point, smoothly turns around and flies there. How can this be implemented?
Game in 2d.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Void59, 2021-11-10
@Void59

I solved the issue this way: I created an object child of the character and used it as a direction of movement. When a new point became a target, the guiding object was rotated to it via Slerp.

M
Morrowind, 2021-11-08
@hekkaaa

Hello.
This can be done using the Random method .

static Random rnd = new Random();
minValue  = 20; 
maxValue = 100;
int result = rnd.Next(minValue  , maxValue ) // Выдает рандомное число в диапазоне которое привязывается к координате. 
// Если точки нужно  X и Y например, то 2 просто повторите rnd.Next.

On the issue of a smooth turn, there are already other solutions. You need to look for solutions, possibly related to the geometry of entering the turn. If more arcade control, then set the maximum angle of rotation per second for example.

N
Nekit Medvedev, 2021-11-09
@NIKROTOS

Bezier curves
https://www.youtube.com/watch?v=EttpoUTSHN0

M
Morgenstern Akhmedovich, 2021-11-09
@Lil_crystal

use Random.Range( min n, max n ), it will return a random value within the minimum and maximum numbers given in brackets.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question