- Home /
Comparing two coordinates in a Vector3
Okay, I'll start of with my code.
public Vector3 z = new Vector3(0,28,0); //it's a Y coordinate, I know
public Vector3 maxroll = new Vector3(0,95,0);
void Update () {
if ((Input.GetAxis("Mouse ScrollWheel") < 0) && ((maxroll[1]-z[1])<= 67)){ // mousewheel back
transform.position += (z*0.2f);
}
}
So my problem is, even when the y-coordinates' distance is way above 67, it doesn't stop the if-condition. But if I say:
"<= 66", the mousewheel won't work. I suspect that the y-coordinate (the z-vector) simply isn't updated.
I hope someone has a solution, and thanks for reading even if you don't ♥
Answer by Gamemaster · Apr 11, 2012 at 11:12 PM
If I'm understanding this correctly, you want to move the object that this script is attached to upwards in the y direction until it reaches the maximum position.
In that case, your two variables aren't changing at all, so maxroll[1]-z[1] will always return 67.
What you need to do is use maxroll[1] - transform.position.y for the comparison.
(note: you can also use maxroll.y looks a little more clear in my opinion)
Answer by Dreoh · Apr 11, 2012 at 09:06 PM
Just skimming and doing a quick reply before I have to log off so sorry if its not necessarily helpful xD
From a cursory glance, seems you may need to use
Vector.Distance(a,b)
As far as I know, maxroll[1]-z[1] does exactly the same as Vector.Distance(maxroll, z). I even used Vector.Distance as a start, and same results came out (can scroll when "<= 67" and above, but not if "<= 66 and below". Thanks for your answer anyway :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Converting an Azimuthal Coordinate to Vector3D? 1 Answer
Game mechanic Tips 0 Answers
How to compare velocity of joint between 2 model in Unity ? 0 Answers