- Home /
Speedometer rotation problem
Hello everybody. I am making a mobile car game, I would like to move the needle in the speedometer from 0 position to 180 position; representing the rotation of my phone . All what matter is to rotate the needle when the mobile rotate. Not necessary to represent the exact angle that the mobile rotated.All i need is the visual feedback, when start rotating the mobile clockwise, the needle should rotate clockwise, and vice versa when anticlockwise. I got z rotation angle for the needle when pointing on 0, then the rotation angle when pointing on maximum value. and made a LERP between them, but the needle does not rotate ,here is the code:-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotationControl : MonoBehaviour
{
static float minAnlge = -43.0F;
static float maxAngle = 222.0F;
static RotationControl thisSpeedo;
// Use this for initialization
void Start()
{
thisSpeedo = this;
}
void Update()
{
//float ang = Mathf.LerpAngle(minAnlge, maxAngle, Time.time);
//thisSpeedo.transform.Rotate (0, 0, ang);
float z = Input.acceleration.x;
for (float ang=-43;ang <= 222; ang = Mathf.LerpAngle(minAnlge, maxAngle, Time.time)
)
{
// if (z > 0)
// {
thisSpeedo.transform.eulerAngles = new Vector3 (0, 0, ang);
//}
//else if (z<0)
// {
// thisSpeedo.transform.Rotate(0, 0, -ang);
// }
}
}
}
Answer by hectorux · Jun 28, 2018 at 11:18 PM
try to dont do that on the for, use it on the update using your ang = Mathf.LerpAngle(currentAngle, angleYouWantToGo, time to achive currentAngle to angleYouWantToGo)
Thanks for answer. I tried it before, and the needle doesn't rotate.
Your answer
Follow this Question
Related Questions
Rotate car steer angle towards target direction 0 Answers
Error car game 0 Answers
Rotate Sprite based on Car Velocity Non GUI 3D Speedometer 0 Answers
Destroyed car styled need for speed? 0 Answers
car game questions 1 Answer