Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
Virtual Accelerometer in Unity

I've seen many tutorials about how to use a smartphone's accelerometer as input to control an object in Unity, but is possible to simulate a tri-axial accelerometer in Unity itself?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can essentially get the "acceleration"(a.k.a the velocity) of an object by dividing the distance covered over time. In this case, that means breaking up a Vector3 into individual xyz variables, then calculating speed on each, and putting them back into a Vector3.

Code:

Vector3 lastPos;

void Start() {
  lastPos = transform.position;
}

void Update() {
  // define velocities as currentPos-lastPos(change) over time per frame, which gets velocity this frame... will be saved every frame
  float xVelocity = (transform.position.x-lastPos.x)/Time.deltaTime;
  float yVelocity = (transform.position.y-lastPos.y)/Time.deltaTime;
  float zVelocity = (transform.position.z-lastPos.z)/Time.deltaTime;
  
  // Do stuff with individual velocities(xyz)
  // ...
  // or store in Vector3
  Vector3 totalVelocity = new Vector3(xVelocity, yVelocity, zVelocity);
  // Do stuff with total velocity
  // ...

  // Set lastPos to transform.position (WARNING: Only do after you are done calculating velocity
  
  lastPos = transform.position;
}

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda