- Home /
Raycast Rotation on Steering Wheel
I am trying to set up a steering wheel and was wonder how to go about detecting a raycast rotation to turn the wheel. Not sure where to start.
Answer by Berenger · Jan 22, 2013 at 03:08 PM
Basically, you want to act as if you had your hand on the whell I guess. You hold a mouse button, then turn the wheel, is that right ?
Raycast on mouse down to know if you're over the wheel, and for that only (you'll need a collider btw, a cylinder would be nice. Then store your mouse position on the screen at that moment, and the position of the center of the wheel, still on screen coordinates. That gives you the vector2D center -> startPoint, and you can now calculate the angle each frame between that vector and center -> currentPoint. Then, set the wheel rotation to that angle.
Close enough. For the mouse pos, you already have Input.mousePosition (the y might be reversed, I always forget that). For the wheel's center, assu$$anonymous$$g the pivot is at it's center, you have WorldToScreenPoint : http://docs.unity3d.com/Documentation/ScriptReference/Camera.WorldToScreenPoint.html
Finally, For the angle, there is the Angle function here : http://docs.unity3d.com/Documentation/ScriptReference/Vector2.Angle.html
Your answer
Follow this Question
Related Questions
How Do I add rotations to one of my objects in my AR application? 1 Answer
How to keep local rotation when using raycasts? 1 Answer
easing a rotation of ROTATE AROUND 1 Answer
Can't figure out how to make my raycast obstacle avoidance less jittery 3 Answers
Change transform.forward while slerping rotations around the transform.forward axis 1 Answer