- Home /
Applying colliders on Bike.
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
Answer by taters · May 28, 2011 at 11:52 PM
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 Physics.IgnoreCollision
on anything that overlaps in the bike, or may collide. If the bike lands hard and the wheel sphere collider goes upwards into the bike collider too hard, it sometimes went through it and couldn't go back. And did that all too familiar physics-goes-nuts thing.
Hey, @tasters, can you tell me how you set that up in the hierarchy?
Answer by taters · Jun 22, 2011 at 04:18 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
Hey why didnt you add Rigidbody on Parent game object? wont it use more memory then just adding on Parent Object. I just added on my parent object and its working great. any reason why did you do that?
Guess not. I dont like putting rigidbodies parented to other rigid bodies though. Strange things happen and physics isn't 'passed up' to the parent (I dont think?). But it's irrelevant in this case anyway, caus you have the springs and joints linking rigidbodies anyway. I'm just a fan of empty game object lol!. I kinda use them like folders. But yeah, you could dump everything in the 'bike frame' in my hierarchy example above and get rid of the top empty game object if you want.
Diagram http://www.pyramid-design.co.uk/temp/lolbike.jpg link is broken
Answer by bcman · Dec 05, 2013 at 12:40 AM
My idea is trying to copy physics as real tire. That's why I've make 9 digressive wheelcolliders as wide as tire. It makes bike more stable. And easy to accelereate/brake by .torque