- Home /
 
Rolling Wheel as a character : dealing with rotations,Moving wheel as a character : dealing with rotation
Hey everyone ! I'm very new to unity and programming, and I'm trying to create a controller for a wheel character (you litterally play a loose wheel rolling), for which I want to use rigidbody. Since the wheel is constantly rotating, I used another object (that copies its position) that controls its y rotation (turning left/right) and where "forward" is (since its z axis is constantly turning). It works pretty well, except from the fact that the wheel stops rotating on the X axis when it reaches 90 or -90 rotation, I spent a lot of time trying things, but I couldn't do it on my own. Here is what I have so far (in case this is isn't clear, the RotationTarget is an empty that copies the Character's position, and whose Yrotation is instructed by the keyboard) :
 public class CharacterMovement : MonoBehaviour
     {
     
       
         private Rigidbody rb;
     
         public GameObject RotationTarget;
     
         private Transform TargetTransform;
       
     
     
     
         void Start ()
     
         {
             rb = GetComponent<Rigidbody>();
             
         }
       
     
         void Update()
         {
       
             
             float vertical = Input.GetAxis("Vertical");
             
           
             // Getting the wheel to roll, works pretty well
             TargetTransform = RotationTarget.GetComponent<Transform>();
             rb.velocity += vertical*TargetTransform.forward * Time.deltaTime*10;
 
 // Getting the wheel to rotate on Y and Z as the Target but on X as it should)
             transform.rotation = Quaternion.Euler (transform.eulerAngles.x, TargetTransform.eulerAngles.y, TargetTransform.eulerAngles.z);
        
     
     
         }
 
 
               Thanks a lot for the help !
Your answer
 
             Follow this Question
Related Questions
How do I rotate my character to face straight depending on which wasd key i press? 0 Answers
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers
Lock Character to Z axis. 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Rigidbody character controller issues 0 Answers