Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

why won't the rotation work on my game?

Discussion in 'Getting Started' started by VincentPardy1, Aug 17, 2023.

  1. VincentPardy1

    VincentPardy1

    Joined:
    Jul 30, 2023
    Posts:
    2
    Here's the script i'm using

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    [RequireComponent(typeof(Rigidbody))]
    public class RotateCharacter : MonoBehaviour
    {
    public float rotationSpeed = 180f; // Adjust this value for rotation speed

    private Rigidbody rb;

    private void Start()
    {
    rb = GetComponent<Rigidbody>();
    }

    private void Update()
    {
    float rotateInput = Input.GetAxis("Rotate");

    // Rotation
    Vector3 rotation = new Vector3(0f, rotateInput * rotationSpeed * Time.deltaTime, 0f);
    Quaternion deltaRotation = Quaternion.Euler(rotation);
    rb.MoveRotation(rb.rotation * deltaRotation);
    }
    }

    I still can't understand why it won't work
     
  2. VincentPardy1

    VincentPardy1

    Joined:
    Jul 30, 2023
    Posts:
    2
    I have a capsuel, with the camera, rigid body, a floor, and that script
     
  3. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    Last edited: Aug 18, 2023