- Home /
Looking for ideas of how to control specific values from C#
We have two types of objects we add dynamically.
They can be rotated differently.
A) can only rotate 90 degrees, so that gives 4 directions {0,90,180,270}
B) can be rotated in 5 degress, so we have {0,5,10,15,20,25,30 ... 355} (you get the idea I think)
Problem is that we make the user rotate the object and we also need to let the user switch from type A to B and back. When switching back to A, we need to make sure that the rotation matches the rule and if it doesnt, then go for the best/nearest angle.
Does this make any sense to you and you have some ideas, please post them. I am stirring at this and cant come up with a nice solution. Only ugly hacks.
Answer by DaveA · Aug 16, 2011 at 08:56 PM
Mathf.Round is your friend
To round to nearest 1, Mathf.Round(value)
To round to nearest 5, Mathf.Round(value/5.0) * 5.0;
To round to nearest 90, Mathf.Round(value/90.0) * 90.0;
oh my.. so pure and simple! I was thinking in terms of $$anonymous$$odulus etc. THAN$$anonymous$$S A LOT!
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Snap object rotation 1 Answer
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to make behaviour respond to a key press but not a hold? 1 Answer