How can I calculate RPM to rotate a monowheel based on Rigidbody velocity?
So I have a monowheel. I was not able to make it work with a wheel collider. I have an empty object that has the following script and a Rigidbody component. As a child I have a wheel model that I want to rotate based on the Parent's velocity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TireController2 : MonoBehaviour
{
public float speed = 5;
public Rigidbody wheel;
public Transform wheelMesh;
// Start is called before the first frame update
void Start()
{
}
void FixedUpdate()
{
transform.position += Vector3.forward * speed * Time.deltaTime;
Rigidbody rb = GetComponent<Rigidbody>();
wheelMesh.transform.Rotate(rb.velocity.x, 0, 0);
}
void Update()
{
}
}
I've tried something like this:
float rpm;
float vel;
float circf = 6.28;
public Transform wheelMesh;
void FixedUpdate()
{
Rigidbody rb = GetComponent<Rigidbody>();
vel = rb.velocity;
rpm = vel/circf
wheelMesh.transform.Rotate(rpm, 0, 0);
}
But it says that Vector3 data cannot be handled as float so I can't use it to calculate RPM.
I don't need the wheel to act realistically just for it to rotate.
Any help would be greatly appreciated.
Comment