looking to try and rotate and object in one axis with a key press and am not able to wrap my head around how this works.
What I am trying to do. have it so the player hits the r key and the object rotates in the Yaxis 90%.
I had this working at one point but it wasn’t smooth. so i looked into making a smooth motion (through a jason Weimenn
) I understand how that works.
But what I think I need to be able to do is get just the X and Z axis of the object have it stay put and then move it 90 on the y. but i cant figure out how to extract and axis rotation.
any help would be appreciated thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tile : MonoBehaviour
{
private Transform startRotPos;
private Transform endRotPos;
private float rotAmount = 90f;
[SerializeField] [Range(0f, 1f)]
float lerpPct;
void Update()
{
endRotPos.rotation = Quaternion.Euler(Input.GetAxis("startRotXPos"), rotAmount, Input.GetAxis("startRotZPos"));
if (Input.GetKeyDown("r"))
{
transform.position = Vector3.Lerp(startRotPos.position, endRotPos.position, lerpPct);
transform.rotation = Quaternion.Lerp(startRotPos.rotation, endRotPos.rotation, lerpPct);
}
}
}