Search Unity

Question How do I rotate my ball the way it is moving?

Discussion in '2D' started by Acidik0196, Jul 26, 2020.

  1. Acidik0196

    Acidik0196

    Joined:
    Jul 26, 2020
    Posts:
    1
    I want to make a game where you control a ball. I want it to be as if it is rolling, so if you are moving left it will roll left, and if it is moving right it will roll right. This is my movement script, I am also using Brackeys's 2d movement script:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Threading;
    4. using UnityEngine;
    5.  
    6. public class PlayerMovement : MonoBehaviour {
    7.  
    8.     public CharacterController2D controller;
    9.  
    10.     float horizontalMove = 0f;
    11.  
    12.     public float runSpeed = 40f;
    13.  
    14.     bool jump = false;
    15.  
    16.     void Update() {
    17.  
    18.         horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
    19.  
    20.         if (Input.GetButtonDown("Jump"))
    21.         {
    22.             jump = true;
    23.         }
    24.     }
    25.  
    26.      void FixedUpdate() {
    27.  
    28.         controller.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
    29.         jump = false;
    30.  
    31.     }
    32. }
    33.  
    Any help would be greatly appreciated as this is my first unity project.