- Home /
How do I display speed of a rotating object?
Hello, I've been researching how to make a display of the speed at which a rotating object is going, but can't find anything.`using UnityEngine; using System.Collections;
public class FingerSwipe : MonoBehaviour {
private float rotationSpeed = 10.0F;
private float lerpSpeed = 1.0F;
private Vector3 theSpeed;
private Vector3 avgSpeed;
private bool isDragging = false;
private Vector3 targetSpeedX;
void OnMouseDown() {
isDragging = true;
}
void Update() {
if (Input.GetMouseButton(0) && isDragging) {
theSpeed = new Vector3(-Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0.0F);
avgSpeed = Vector3.Lerp(avgSpeed, theSpeed, Time.deltaTime * 5);
} else {
if (isDragging) {
theSpeed = avgSpeed;
isDragging = false;
}
float i = Time.deltaTime * lerpSpeed;
theSpeed = Vector3.Lerp(theSpeed, Vector3.zero, i);
}
transform.Rotate(Camera.main.transform.up * theSpeed.x * rotationSpeed, Space.World);
transform.Rotate(Camera.main.transform.right * theSpeed.y * rotationSpeed, Space.World);
}
}`
Check out this tutorial on how to display Score and Text: https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/displaying-score-and-text
It's pretty much the same concept, just make a unity GUI text on your screen and reference the rotation speed to change it's values to that. (make sure to change "rotationSpeed" to a public float if you're gonna reference it from another script)
Your answer
Follow this Question
Related Questions
Rigidbody rotation: Use hinge joint motor or MoveRotation script? 0 Answers
Object Rotation/Character Speed 1 Answer
turning a project using AddTorque 0 Answers
[C#] Rotate Turret, Only On X and Z Axis 2 Answers
Change mouse rotation point 1 Answer