- Home /
Best solution for steering a motion controlled bike in VR
I have set up a bike connected to a TacX bike trainer so that it can be used to ride around in VR. I'm using the Advanced ANT+ plugin from the asset store to get the raw input from the trainer to directly set the velocity of a rigidbody to control its speed, which works well and feels natural. The player rides on a virtual bike track that is completely flat, to reduce simulation sickness.
Steering has been more tricky, however. I have taped a HTC Vive controller to the handlebar of the bike and I use the rotation of the controller compared to its rotation at game start as input to inform the virtual bike's steering. I'm a complete beginner at C#, though I have some previous scripting knowledge in other languages. I have found a solution for steering that works, but does not feel natural. Below is the relevant part of the script (fec is a prefab holding the input from the bike trainer):
public void FixedUpdate()
{
Rigidbody rb = GetComponent<Rigidbody>();
rb.velocity = (new Vector3(transform.forward.x, 0f, transform.forward.z)) * (fec.speed*0.5f);
transform.forward = Vector3.Lerp((new Vector3(transform.forward.x, 0, transform.forward.z)), (new Vector3(lctrl.transform.forward.x, 0, lctrl.transform.forward.z)), 0.00225f*fec.speed);
transform.position = new Vector3(transform.position.x, 0f, transform.position.z);
}
This kind of steering works, but does not feel like actually steering a bike. The bike drifts in corners and the speed of turning sometimes feels too slow and sometimes too fast depending on the speed you are going. I originally had a different solution where I used wheel colliders, which worked great for steering, but which I did not manage to get working with setting velocity directly.
I've tried to read up on the physics of steering and various tutorials on turning and steering, but have not been able to successfully solve this yet. Any input on what I can do to make steering feel more natural is greatly appreciated.
@shmupemup, I am also doing a similar project and have also downloaded the advance ant+ package from the asset store but i am not able to understand how do i move the bicycle in the game when i pedal my cycle in the real world...could you please help me with that