Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

632
Views
¿Cómo puedo obtener un movimiento aleatorio suave (Unidad 2D)?

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; } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!