- Home /
puzzle with rotating statues
Hello everyone , I'm working on a Unity game and I'm seeking help , i've begun a game with Unity3D which you can try here http://ns14.freeheberg.com/~anykey2/Test1/WebPlayer/WebPlayer.html
I'd like to include some puzzles , I've begun with a puzzle that seems easy to do , but it's actually very hard for me (I'm a weak programmer) I'd like to put some kind of statues that you must rotate with buttons on the ground until they are all at y=0 (they face the camera all in the same direction) so it opens a gate. Here is what my script looks like , but it really doesn't work a little precision , i'd like to use Rotate , not rotation to have slow and realistic rotations.
var Statue : GameObject;
var Porte : GameObject;
var RotationLimit =0;
static var StatuePoint = 0;
function Update () {
if (Statue.transform.rotation.y > 360){
Statue.transform.rotation.y = 0;
}
if (RotationLimit == 4){
RotationLimit = 0;
}
if (Statue.transform.rotation.y == 90){
RotationLimit = 1;
}
if (Statue.transform.rotation.y == 180){
RotationLimit = 2;
}
if (Statue.transform.rotation.y == 270){
RotationLimit = 3;
}
if (Statue.transform.rotation.y == 0){
RotationLimit = 0;
}
if (RotationLimit == 0){
++ StatuePoint;
}
print(RotationLimit);
}
function OnTriggerStay (other : Collider) {
if (other.gameObject.tag == "Boite" && RotationLimit == 0 && Statue.transform.rotation.y <= 90 && Statue.transform.rotation.y >= 0){
Statue.transform.Rotate(0,5,0);
}
if (other.gameObject.tag == "Boite" && RotationLimit == 1 && Statue.transform.rotation.y <= 180 && Statue.transform.rotation.y >= 90){
Statue.transform.Rotate(0,5,0);
}
if (other.gameObject.tag == "Boite" && RotationLimit == 2 && Statue.transform.rotation.y <= 270 && Statue.transform.rotation.y >= 180){
Statue.transform.Rotate(0,5,0);
}
if (other.gameObject.tag == "Boite" && RotationLimit == 3 && Statue.transform.rotation.y <= 360.1 && Statue.transform.rotation.y >= 270){
Statue.transform.Rotate(0,5,0);
}
}
function OnTriggerExit (other : Collider) {
RotationLimit = RotationLimit +1 ;
}
$$anonymous$$y problem is , the statue turns , but it doesn't stop at 90° and after at 180° and after at 270° , but it does stop at 4° after making a full rotation , I'd like my statue to stop at 90° , 180 ° ... and give it a value for each quarter of full rotation and for the 0° position , the good value , if the 4 statues have the good value , it opens the door , actually StatuePoint was a test to open the door , every statue increases the statue point when the statue is at 0° and when the 4 are at 0° (StatuePoint =4) , the gameObject door open , but the script doesn't work from the beginning , so it is actually useless right now Thanks for trying to help , I appreciate , especially it was my birthday yesterday
Answer by Waz · Jul 26, 2011 at 10:34 PM
Your logic is basically correct, except that you increase StatuePoint ever frame and never decrease it. I assume that's supposed to be a counter of how many are correctly positioned.
Yeah that's right, I've mistaken this var , but the whole script doesn't work well actually =/
Your answer
Follow this Question
Related Questions
Smooth rotation in 90° increments 0 Answers
Euler angle problems with rotation limit script 3 Answers
How can I set a limit to my object rotation???(Here's the code) 2 Answers
Need help with limiting rotation. 1 Answer
Puzzle open door ? 1 Answer