yesimarobot
yesimarobot

Reputation: 283

Random 2d movement (similar to flies) in Unity3d

I want to add random movement to some of my game objects similar to the way flies swarm in Unity3D. I've developed a method using the addforce() method but would like to bypass the physics engine.

Any help is appriciated

Upvotes: 3

Views: 9726

Answers (1)

smokris
smokris

Reputation: 11850

Simple 2D random movement:

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);
}

Upvotes: 3

Related Questions