- Home /
How do i determin if an objects rotation is between 2 values on each axis?
im currently making a small game where you have to rotate an object until its shadow fits the outline. at the moment its really hard to play because i cant seem to rotate the object to fit the shadow. i thought to make it easier i would make it so you can be outside the parameters of filling it so for example for the shadow to fit the outline the object needs to be -90,0,0 but i want to make it so that the shadow moves into place when you are within the parameters of -70 to -110, -20 to 20, -20 to 20.
how would i go around doing this and if you know some code that makes it easier to rotate the object by dragging your mouse around with the key down then please help!!
what i have so far: using UnityEngine;
namespace RakibUtils { public class secondrotate : MonoBehaviour { [SerializeField] private LayerMask targetLayer; [SerializeField] private float rotationRate = 3.0f; [SerializeField] private bool xRotation; [SerializeField] private bool yRotation; [SerializeField] private bool invertX; [SerializeField] private bool invertY; [SerializeField] private bool touchAnywhere; private float m_previousX; private float m_previousY; private Camera m_camera; private bool m_rotating = false;
public Transform originalRotationValue;
[SerializeField] private float rotationResetSpeed = 1.0f;
private void Awake()
{
m_camera = Camera.main;
originalRotationValue = gameObject.transform;
}
private void Update()
{
if (!touchAnywhere)
{
//No need to check if already rotating
if (!m_rotating)
{
RaycastHit hit;
Ray ray = m_camera.ScreenPointToRay(Input.mousePosition);
if (!Physics.Raycast(ray, out hit, 1000, targetLayer))
{
return;
}
}
}
if (Input.GetMouseButtonDown(0))
{
m_rotating = true;
m_previousX = Input.mousePosition.x;
m_previousY = Input.mousePosition.y;
}
// get the user touch input
if (Input.GetMouseButton(0))
{
var touch = Input.mousePosition;
var deltaX = -(Input.mousePosition.y - m_previousY) * rotationRate;
var deltaY = -(Input.mousePosition.x - m_previousX) * rotationRate;
if (!yRotation) deltaX = 0;
if (!xRotation) deltaY = 0;
if (invertX) deltaY *= -1;
if (invertY) deltaX *= -1;
transform.Rotate(deltaX, deltaY, 0, Space.World);
m_previousX = Input.mousePosition.x;
m_previousY = Input.mousePosition.y;
}
if (Input.GetMouseButtonUp(0))
{
m_rotating = false;
}
//this next bit doesnt work...![alt text][1]
if (transform.eulerAngles.y >= -20 && transform.eulerAngles.y <= 20)
{
if (transform.eulerAngles.x >= -70 && transform.eulerAngles.x <= -110)
{
transform.rotation = Quaternion.Slerp(transform.rotation, originalRotationValue.rotation, Time.time * rotationResetSpeed);
}
}
}
}
}
Blockquote
Blockquote
[1]: /storage/temp/192373-reflected-screenshot.png
,im currently making a small game where you have to rotate an object until its shadow fits the outline. at the moment its really hard to play because i cant seem to rotate the object to fit the shadow. i thought to make it easier i would make it so you can be outside the parameters of filling it so for example for the shadow to fit the outline the object needs to be -90,0,0 but i want to make it so that the shadow moves into place when you are within the parameters of -70 to -110, -20 to 20, -20 to 20.
how would i go around doing this and if you know some code that makes it easier to rotate the object by dragging your mouse around with the key down then please help!!
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Multiple Cars not working 1 Answer
How can I limit the rotational speed of a gameObject tracking my mouse? 1 Answer
how do i make first person character rotate left and right along with camera? 0 Answers
How to make the calculated angle respective of the players rotation? 1 Answer