- Home /
 
 
               Question by 
               IceEnry__lol · Mar 05, 2017 at 03:37 PM · 
                rotationplayerplayer movementcubemoving  
              
 
              Moving and rolling a cube
Hi, i have already read some questions like this and I have also found not simple scripts that work but I can't understand it. I have to move the player, a cube with a rigidbody (on the x axis) and everytime it does a step it will rotates of 90 degrees, how can I do it (is better via script or animation/animator, and how)? Actually my movement script is this (the cube rotates "physically", but not in the "correct way" with the freeze rotation on the z axis turned off)
  using UnityEngine;
  using System.Collections;
  public class mov : MonoBehaviour
  {
      public float velocità;
      private Rigidbody rb;
      public bool IsGrounded;
      public int jumpP;
      void Awake(){
          IsGrounded = true;
          rb = GetComponent<Rigidbody> ();
          jumpP=10;
      }
      void OnCollisionEnter(Collision other){    
              IsGrounded = true;
  
      }
      void FixedUpdate()
      {
          float movevert = Input.GetAxis ("Vertical");
          float movehoriz = Input.GetAxis ("Horizontal");
          Vector3 movement = new Vector3 (movehoriz, 0.0f, movevert);
              rb.velocity = rb.velocity + movement * velocità/2;
          if (IsGrounded == true) {
              if (Input.GetButton ("salto")) {
                  rb.velocity = new Vector2 (0f, jumpP);
                  IsGrounded = false;
              }
          }
  
      }
  }
 
              
               Comment
              
 
               
              Answer by thomasfriday · Jul 10, 2021 at 03:19 PM
Here's a short Youtube video that covers exactly how to roll a cube on its edges: https://youtu.be/06rs3U2bpy8

Your answer