|
I'm trying to use a wheel collider in a school project and was wondering A)how to script it to work with Input.GetKey() with the up arrow increasing the motorTorque.B)will it react with the terrain object moving the bike forward?? Any answers would be appreciated.
(comments are locked)
|
|
Wheel colliders aren't easy things to control, when making a bike or motor you'll have to do some tricks to make it stable (not falling) as the wheel collider is infinitely thin. Below I wrote a simple motor script (that doesn't solve the falling over problem, but set y of centerOfMass property to negative values does help). Because the wheelcolliders shouldn't rotate with the wheels, you need to set up the motor as follows for the script, the motor has two wheel attach gameobjects (frontwheelattach and backwheelattach), you must add the wheelcolliders to these nodes (and attach these to the script properties front/backWheelCollider). The attach nodes must have the actual wheels attached, and these should be connected to the script front/backWheelTransform. If you need a demo project to see how to setup the script I could make something quick for that as well, just let me know. thanks a lot, i put it in my project and assigned the wheel colliders for the front and back wheel but everytime i run it the wheels move to the center of the bike. Any suggestions?
Mar 22 '10 at 03:50 PM
JDubs212
i've also got a problem with changing the motorPower using keyboard input
Mar 22 '10 at 11:41 PM
JDubs212
I had the same problem with the wheels moving to the center of my vehicle. First I found that when my vehicle came to a rest the collider.GetGroundHit function would return false and I also noticed that (localPosition = -Vector3.up * collider.suspensionDistance;) would set the local postion to (0,-suspensionDistance,0) which would be the pivot point of the parent object in most cases the center of the vehicle. Any body know why the GroundHit would return false just because the collider is at rest?
Sep 16 '10 at 02:18 PM
Kevin Ambruster
(comments are locked)
|
|
I fixed the problem by myself (I'm so proud now :D) the reason of the wheels sticking in the middle of the vehicle is that in our UpdateeWheelHeight function there is this last line of code to be replaced: wheelTransform.localPosition = localPosition; with this: wheelTransform.localPosition.y = localPosition.y; it's just that we have to control JUST and ONLY y axis of our wheels, not all 3 of them. so when the vehicle was in the air the code was repositioning the object on all of the axis - moving the whole wheel to (0,-suspensionDistance,0) in local coordinates. PS: I found another minor mistake here: localPosition = -Vector3.up * collider.suspensionDistance; it would be a better idea to subtract a radius of wheel from suspension distance: localPosition = -Vector3.up * (collider.suspensionDistance - collider.radius); Kevin: GetGroundHit is intended to produce false when the colider is in the air. that's why we are using the if statement :).
(comments are locked)
|
