Hello!
I’ve read some posts here on how to rotate an object on z, but i can’t seem to get it to work with the tutorial i’m walking through. Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed = 4;
public float speed2 = -4f;
// Start is called before the first frame update
void Start()
{
// sets initial position of player
transform.position = new Vector3(0, 0, 0);
}
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
float zLeft = Input.GetAxis("zLeft");
float zRight = Input.GetAxis("zRight");
// want to roll object slightly on z axis to simulate a ship banking.
transform.Translate(new Vector3(horizontalInput, verticalInput, zLeft) * speed * Time.deltaTime);
transform.Translate(new Vector3(0, 0, zRight) * speed2 * Time.deltaTime);
}
}
My goals are as follows - 1) rotate the object on the x axis whenever zLeft and zRight are in use, and when i release the key level out to its original rotation. 2) I’m suspecting there is an easier way to accomplish my last line of code with out defining a negative variable.