Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Sonido de motor

Iniciado por Gastonspas, Marzo 18, 2018, 11:16:43 PM

Tema anterior - Siguiente tema
Hola muy buenas a tod@s, tengo una duda alguien sabe como se puede "simular" el sonido de motor en un juego de autos dejo el script mas abajo por si es que no sirve me avisen, no pido que me lo den en bandeja y mucho menos en bandeja de oro, solo pido que me digan alguna que otra cosa para que tenga en cuenta para poder hacerlo 
 
uso unity 2017.3.1f1
 
 
 

using UnityEngine;
using UnityEngine.UI;
using System;
[Serializable]
public enum DriveType
{
RearWheelDrive,
FrontWheelDrive,
AllWheelDrive
}
public class WheelDrive : MonoBehaviour
{
public float maxAngle = 30f;
public float maxTorque = 300f;
public float brakeTorque = 30000f;
public float criticalSpeed = 5f;
public int stepsBelow = 5;
public int stepsAbove = 1;
public DriveType driveType;
public Rigidbody auto_vel;
public float velo = 0f;
public Text ui;
private WheelCollider[] m_Wheels;
public int stop_taller = 0;
public float sus = 0f;
public float sus_new = 0f;
void Start()
{
   m_Wheels = GetComponentsInChildren<WheelCollider> ();
   for (int i = 0; i < m_Wheels.Length; ++i) {
      m_Wheels [i].brakeTorque = 0f;
   }
}
void Update()
{
   float torque = 0f;
   m_Wheels[0].ConfigureVehicleSubsteps(criticalSpeed, stepsBelow, stepsAbove);
   velo = (auto_vel.velocity.magnitude * 3.6f);
   float angle = maxAngle * Input.GetAxis("Horizontal");
   if (Input.GetAxis ("Vertical") < 0.0f)
         torque = -650.0f;
   else
         torque = maxTorque * Input.GetAxis ("Vertical");
   
   float handBrake = Input.GetKey(KeyCode.Space) ? brakeTorque : 0;
   foreach (WheelCollider wheel in m_Wheels)
   {
      if (stop_taller == 1) {
         wheel.motorTorque = 0f;
         wheel.steerAngle = 0f;
         wheel.brakeTorque = 0f;
      }
      if (wheel.transform.localPosition.z > 0 && stop_taller == 0) {
         wheel.steerAngle = angle;
         wheel.brakeTorque = handBrake;
      }
      if (wheel.transform.localPosition.z < 0 && stop_taller == 0) {
         wheel.brakeTorque = handBrake;
      }
      if (wheel.transform.localPosition.z < 0 && driveType != DriveType.FrontWheelDrive && stop_taller == 0) {
            wheel.motorTorque = torque;
      }
      if (wheel.transform.localPosition.z >= 0 && driveType != DriveType.RearWheelDrive && stop_taller == 0) {
            wheel.motorTorque = torque;
      }
         
      Quaternion q;
      Vector3 p;
      wheel.GetWorldPose (out p, out q);
      Transform shapeTransform = wheel.transform.GetChild (0);
      shapeTransform.position = p;
      shapeTransform.rotation = q;
   }
   ui.text = "Velocidad: "  + Mathf.RoundToInt (velo) + " (Km/h)  | Rpm: " + Mathf.RoundToInt (torque);
}
public void sus_original()
{
   foreach (WheelCollider wheel in m_Wheels) {
      sus = wheel.suspensionDistance;
   }
}
public void Suspension()
{
   foreach (WheelCollider wheel in m_Wheels) {
      wheel.suspensionDistance = sus_new;
   }
}
}

 
 

este tutorial puede ayudarte:
 


   
eature=oembed" width="480">

 
 
 
o usa un asset:
 
https://assetstore.unity.com/packages/tools/audio/realistic-engine-sounds-lite-94797?aid=1101l3r5B&utm_source=aff

Cita de: Braltor date=1521425562este tutorial puede ayudarte:
   
   

      
         
eature=oembed" width="480">
      
   
   
       
   
   
      o usa un asset:
   
   
      https://assetstore.unity.com/packages/tools/audio/realistic-engine-sounds-lite-94797?aid=1101l3r5B&utm_source=aff
   


Gracias pero, el vídeo no me explica casi nada, y el asset pago no quiero ni tampoco gratis, prefiero hacerlo e ir mejoran dolo, pero no encuentro una base de guía

Tienes que ir variando el Pitch del audio en relación a las revoluciones, luego vas buscando las variantes para el cambio de marchas etc ... 
 
Con eso podes empezar, la magia del audio "Acelerando" es justamente la variación de atributo Pitch del componente Audio Source.
 
La ecuación para el Pitch sería la siguiente 
 

float pitch = 1 + ((velocidadActual - RevolucionesMinimaDeLaMarchaActual) / (RevolucionesMaximaDeLaMarchaActual - RevolucionesMinimaDeLaMarchaActual));

 
Espero te sea de ayuda

Cita de: francoe1 date=1521571808Tienes que ir variando el Pitch del audio en relación a las revoluciones, luego vas buscando las variantes para el cambio de marchas etc ... 
   
   
      Con eso podes empezar, la magia del audio "Acelerando" es justamente la variación de atributo Pitch del componente Audio Source.
   
   
      La ecuación para el Pitch sería la siguiente 
   
   

float pitch = 1 + ((velocidadActual - RevolucionesMinimaDeLaMarchaActual) / (RevolucionesMaximaDeLaMarchaActual - RevolucionesMinimaDeLaMarchaActual));

   
      Espero te sea de ayuda
   


Gracias voy a probar suerte

Etiquetas: