How to fix freeze rotation problem? Please help me someone

It might be easier if you post your code in as text, I can’t make out any of that in the video :sweat_smile:

Hi,

I don’t know in which lecture are you but Ben fixes the rotation issue in lecture “Spit & Polish” (currently #72).

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

public class Rocket : MonoBehaviour
{
Rigidbody rigidBody;
AudioSource audioSource;

// Start is called before the first frame update
void Start()
{
    print("Hello world");
    rigidBody = GetComponent<Rigidbody>();
    audioSource = GetComponent<AudioSource>();
}

private void Rotate()
{
    rigidBody.freezeRotation = false; // take manual control of rotation
    
    if (Input.GetKey(KeyCode.A))
    {
        transform.Rotate(Vector3.forward);
    }

    else if (Input.GetKey(KeyCode.D))
    {
       transform.Rotate(-Vector3.forward);
    }

    rigidBody.freezeRotation = true; // resume physics control of rotation
}

void Thrust()
{
    if (Input.GetKey(KeyCode.Space))
    {
        rigidBody.AddRelativeForce(Vector3.up);

        if (!audioSource.isPlaying)
            audioSource.Play();

    }
    else audioSource.Stop();
}

// Update is called once per frame
void Update()
{
    print("second");
    Thrust();
    Rotate();
}

}

Thank you

Did that lecture fix the issue for you?


See also:

Yes. A little bit. It looks better :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms