Random 2-dimensional (fly-like) movement in Unity3d

I want to add random movement to some of my game objects, similar to how flies swarm in Unity3D. I developed a method using the addforce () method, but would like to get around the physics engine.

Any help is determined

+3
source share
1 answer

Simple 2D random move:

var speed = 0.5;

function Update () {
    transform.position = Vector3.Lerp(transform.position,
                     transform.position + Vector3((Random.value-0.5) * speed, 0, 
                     (Random.value-0.5)*speed), Time.time);
}
+3
source

Source: https://habr.com/ru/post/1723425/


All Articles