Hello guys, I have a bike and i have applied wheel colliders on its wheels. but on other parts of bike i am really confused which collider will be best suitable for them. so can anyone please guide me about it. and also when i move my bike with speed and if it hits the fence on the side of the road, my bike starts flying in air. i have also applied rigidbody and i am applying relative force to move the bike.
kindly guide me to right path it will be really appreciative. thanks
asked May 28 '11 at 10:42 AM
Hi, I've made a bike with physics but slightly different to yours. I tried the wheel colider, but it wasn't realy suitable for me as it works by casting a ray from the wheel downwards to find the floor or whatever. It's not really a 'wheel'. Fine for cars, but it doesn't detect the edge of the wheel, so won't 'collide' if you roll an exposed wheel forwards into something.
So, my solution was a sphere collider. This behaved better as I could just apply relative torque to it, just like a real bike. o.k as long as nothing went near the sides of the wheels, or you went throught thin passage, but my bike was locked on one axis anyway so it didnt matter.
This was then linked to an object that was then linked as a configurable joint to the main bike. This was set locked on all position, and free on one axis so it hinged like the back arm (whatever its name is!) on a real bike. Then limit and spring was set i think. Same deal for the front, apart from the configurable joint was locked on all rotations, and free on one position motion. so it could slide up and down like shocks. Again, limits and springs used I think.
Not sure why yours flies in the air, but I'd bet it's something to do with the wheel collider and adding force.
I'd also recomend using
answered May 28 '11 at 11:52 PM
In terms of the hierarchy, I would have an empty game object called bike. Then inside that, I'd add all the objects. So, you would have something like:
bike <- empty game object |_ front wheel <- RB. add sphere collider and config joint to allow x rotation only, fix to fork |_ front fork <- RB. Add config joint to allow z motion only (limited), fix to bike frame |_ bike frame <- RB. add collider box(s) or mesh or whatever |_ back fork <- RB. add hinge joint with spring. fix to bike frame. |_ back wheel <- RB. add sphere collider and config joint to allow rotation only, fix to back fork (RB = rigidbody)
If any colliders overlap, make them ignore each other in the physics calculation as mentioned earlier. I didn't bother with colliders on the forks.
Obviously it depends on your objects / models and what axis / orientation they are on. e.g you may need rotation to be on the z on the wheel etc.
You could start by using fixed joints on the forks. So fix them to the bike frame, then have config joints on the wheel fixed to the forks. This would get it going so you could add torque to the thing and wizz it along, but there wont be any suspension. Thats where the config joints come in. So i'd start by getting that working then adding the config joints after (otherwise you could be spending ages scratching your head with the config joints, and it turns out the wheel axis are wrong or something)
May be easier to explain myself with a diagram
answered Jun 22 '11 at 04:18 PM