im using Random.onUnitSphere to simulate bubbles floating around jostling for position. It works well although the movement is too “jerky”. I’d like to create the same effect but slow it down and make smoother random movements. Is there anyway I can easily achieve this? Here’s my code:
private void Update()
if (floaty == true)
rb.AddRelativeForce(Random.onUnitSphere * speed);
speed = 0.06f;
Try to multiple it by
Time.deltaTime for more stable movement an for random direction try to mutiple it with
new vector3((Random.Range(-1.0f, 1.0f), (Random.Range(-1.0f, 1.0f),0). if you need like acceleration or deceleration movement you need multple it by
AnimationCurve, Animation Curve is about interpolation movement.
Hope it help.
Here is a simple one.
but it uses
Random.Range if you can get the next position of the game object you might be able to use it.
//used methods to seperate just edit it then it's done
public float Speed = 5f;
private float x;
private float y;
private Vector2 NextPos;
//the first number is included the last number is not in Random.Range
x = Random.Range(3, 10);
y = Random.Range(3,10);
NextPos = new Vector2(x,y);
transform.position = Vector2.MoveTowards(transform.position, NextPos, Speed);