Hi all, first time posting because I’m usually pretty confident in my scripting, but when it comes to rotations I’m a total noob!
At the moment, i’m trying to move an object on its local x-axis by ± 30 degrees.
I have two functions at the moment:
private void TurnBuckleOne() {
var wantedVal = Mathf.Lerp(-30, 0, turnBuckle1);
antenna.localEulerAngles = new Vector3(wantedVal, antenna.localEulerAngles.y, antenna.localEulerAngles.z);
}
private void TurnBuckleTwo() {
var wantedVal = Mathf.Lerp(30, 0, turnBuckle2);
antenna.localEulerAngles = new Vector3(wantedVal, antenna.localEulerAngles.y, antenna.localEulerAngles.z);
}
Where turnBuckle1 and turnBuckle2 are values from 0 → 1. These values are controlled individually by a slider/another function which calls either TurnBuckleOne or TurnBuckleTwo respectively everytime the percent changes. At the moment, both these values start at 1.
at the moment, these two work perfectly fine individually!
Turnbuckle one successfully moves the angle between 330 → 0
Turnbuckle two successfully moves the angle between 0 → 30
However, my problem comes when I want both of them to interact with each other. So for example, if I use TurnBuckleOne and its local euler axis goes to 350 for example, I then want to be able to use TurnBuckleTwo but can still only be within the range. My intention is that since the range for TurnbuckleTwo can only move up to +30 degrees, by changing the slider, the new effective localEuler angle range should be between 350 → 380 (20 when looping).
For context, I’ve tried the following, but can’t seem to quite get it. I’ve tried using mathf.LerpAngle but perhaps I’m using it wrong. But the second one that I was sure that would work is that everytime I switch between the functions, I set an “AnchorAngle” which sets where the current angle was. That way, when I switch to the other function it knows the range in which it can start. My best guess is that my Lerp is off/not doing what I want?
private void TurnBuckleOne() {
if(index != 1)
{
anchorAngle = antenna.localEulerAngles;
index = 1;
}
var wantedVal = Mathf.Lerp(anchorAngle.x-30, anchorAngle.x, turnBuckle1);
antenna.localEulerAngles = new Vector3(wantedVal, antenna.localEulerAngles.y, antenna.localEulerAngles.z);
}
if(index != 2)
{
anchorAngle = antenna.localEulerAngles;
index = 2;
}
private void TurnBuckleTwo() {
var wantedVal = Mathf.Lerp(anchorAngle.x + 30, anchorAngle.x, turnBuckle2);
antenna.localEulerAngles = new Vector3(wantedVal, antenna.localEulerAngles.y, antenna.localEulerAngles.z);
}
Happy to discuss because this is the longest I’ve been stuck on a problem in a while and I’m thinking it’s a simple fix that I’m hopefully just not understanding for some reason ahha, thanks for reading!