- Home /
Square wheels
I know how to use wheelcollider, but how would one go about creating a car with square wheels instead of round? The wheels would need to be capable of different grip settings, and also work with other shapes like triangle and round.
Answer by GraviterX · Sep 18, 2014 at 12:05 AM
It depends on what you want to do. If you want the car to drive on it's own, then I would recommend using an animation, that way you could edit how the wheels move. If you want the player to move it, I would recommend playing with colliders. I haven't done anything like this so I'm sorry if I'm not specific. Hope this helps.
I am speaking of a drivable vehicle with motor, and animation is not an option since the wheels will have to collide correctly with bumpy terrain
Answer by Cherno · Sep 18, 2014 at 12:14 AM
The wagon would move up and down as the square wheels turn, so you can just determine the wagon's y offset from the transform.rotation.eulerangles of one of the wheels (assuming that they all turn the same). I would keep a root object on ground level and make the wagon a child of it, so it can move up and down without changing the actual position of the object.
In essence, you would rotate the wheels by code depending on speed, and don't give them any actual colliders with rigidbodies that react with the ground. The forward and backward movement of the wagon would still be accomplished by rigidbody and velocity setting, but it just needs a normal box colider with flat bottom that sits on the ground.
The wheels do not necessarily allign, in fact they might not even all be of same shape. The whole point of the odd wheels is to navigate a terrain with obstacles and such with non-generic wheels. Realistic physics is of top priority
Answer by Kiwasi · Sep 18, 2014 at 10:12 AM
This could be achieved with a hinge joint (in 3D physics anyway). Simply place the hinge at the center of the wheel with the anchor facing into the vehicle. Use add torque to make them turn. If you really wanted you could attach these to an axel and add suspension with spring joints.
To be realistic your square wheeled vehicle won't be moving very fast. You probably don't need all of the fancy high velocity stuff a wheel collider provides.
This sounds more like what I need. I've been messing with hinge joints and they all seem sort of "sloppy", as in the wheel appears to be mounted on a rubber band contraption. Can you upload me a simple example on how to do it?
Answer by ViCoX · Sep 18, 2014 at 01:04 PM
This is an idea not the implementation. Heres example You could raycast from bounding box vertices to the ground collider. Get the closest point and get its difference and match the box wheel to the ground. Then make it rotate so that it spins on the ground? I haven`t tested this so hard to say the best solution. : ) I hope it helps.
Again, this would look nice but wouldn't quite pull off on a bumpy terrain