Estoy usando Random.onUnitSphere para simular burbujas que flotan y se empujan por una posición. Funciona bien aunque el movimiento es demasiado "entrecortado". Me gustaría crear el mismo efecto pero reducir la velocidad y hacer movimientos aleatorios más suaves. ¿Hay alguna forma en que pueda lograr esto fácilmente? Aquí está mi código:
private void Update() { if (floaty == true) { rb.AddRelativeForce(Random.onUnitSphere * speed); speed = 0.06f; } }Un caminante aleatorio de ruido Perlin debería funcionar
//There are probably better ways to do this. Vector3 RandomSmoothPointOnUnitSphere(float time) { //Get the x of the vector float x = Math.PerlinNoise(time, /* your x seed */); //Get the y of the vector float y = Math.PerlinNoise(time, /* your y seed */); //Get the z of the vector float z = Math.PerlinNoise(time, /* your z seed */); //Create a vector3 Vector3 vector = new Vector3(x, y, z); //Normalize the vector and return it return Vector3.Normalize(vector); }Y en la función Actualizar
if (floaty) { //Get the vector Vector3 movementvector = RandomSmoothPointOnUnitSphere(Time.time); //You can also use CharacterController.Move() transform.Translate(movementvector * Time.deltatime); }También debo mencionar que este enfoque no debería funcionar con RigidBody.ApplyForce(), pero normalmente no uso la física predeterminada de Unity, por lo que podría funcionar. De todos modos, no debería cambiar nada.