I know some of you already are prepared to give me the typical response of "just google it" I'm stuck on this phase for about an hour now, I did rotate things in the past.
But I literally can't understand why when I rotate the barrel with code, it will rotate on the y and z axis as well, I want to lock those 2 axis to 0 and -90.
Here is a video of the problem I have:
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExplosiveBarrel : MonoBehaviour
{
public float barrelSpeed = 2f;
public float rotationSpeed = 10f;
void Update()
{
// Making the Barrel move on the road
Vector3 newPos = new Vector3(0, 0, -1f * barrelSpeed * Time.deltaTime);
transform.position += newPos;
// Spinning the Barrel on the X axis
transform.Rotate(1f * rotationSpeed * Time.deltaTime, 0f, 0f);
}
}
Please explain what did I do wrong, I plan to do small projects to expand my knowledge but I'm stuck here for some reason.
Thank you in advance!