- Home /
Locking rotation of WheelCollider
Hello! I'm not sure if this has been asked before or not, but i couldn't find anything. What i'm trying to do is using the Mouse to rotate WheelCollider, but when i do that it just rotates back again.
Currently i'm using this code:
public WheelCollider FrontLeftWheelCollider;
public WheelCollider FrontRightWheelCollider;
public float MouseSteering = 10.0f;
void Update()
{
FrontLeftWheelCollider.steerAngle = MouseSteering * Input.GetAxis("Mouse X");
FrontRightWheelCollider.steerAngle = MouseSteering * Input.GetAxis("Mouse X");
}
Any ideas on how to make it rotate the WheelCollider with the Mouse X axis, and keep it locked at that rotation?
Or do i need to write a completely new script for that?
void Update()
{ if(Input.Get$$anonymous$$ouseButton(0))
{
FrontLeftWheelCollider.steerAngle = $$anonymous$$ouseSteering * Input.GetAxis("$$anonymous$$ouse X");
FrontRightWheelCollider.steerAngle = $$anonymous$$ouseSteering * Input.GetAxis("$$anonymous$$ouse X");
}
}
It will only work if left mouse button is pressed.
Thanks for the reply, unfortunately it didn't lock the rotation of the WheelCollider, ins$$anonymous$$d it only made it possible to rotate when Left $$anonymous$$ouse button is hold down. Am i not clear enought? Do i need to specify my question better? Thanks for helping though :)
Actually, the only way to lock it is that you dont update the Input, meaning you will have to restrict the input, since you have put the above code in an Update function, it will run regardless, so in order to lock it, you need another event which controls the input. What I suggested is just another event.
You are polling new input every frame + updating the angle, if you want to lock the angle, you either have to stop the "update" on either the angle or the Input, if both are always updating every frame, you cant actually have a "lock" mechanism.
Sorry for the very late reply! Well that sounds quit logic, unfortunately i'm not good enought at program$$anonymous$$g so i'm going to learn more before getting into Unity3D again.. So all that with events, i'm not really sure about how to do it, but i get the point! Thanks for taking your time and helping :)
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Steering Wheel with mouse drag 0 Answers
Multiple Cars not working 1 Answer
Angry Birds Style Loader (Load the Birds to be fired) 0 Answers
Check if mouse cursor is locked 1 Answer