Forum rules - please read before posting.

Rotation puzzle variable(?) question

edited July 2014 in Technical Q&A
Hi,

I have 4 kinds of object. Imagine they are mirrors and they must reflect the sun rays in proper way.

I create 4 hotspot for each object. Each hotspot can rotate the objects  90 degree on click. They are working perfect.

After the player adjust them on correct way, the door should be open, or something will happen.

So I need a script something like which says "if object 1 (90), if object 2 (180), if object 3 (270), if object 4 (0) degree, start bla bla"

So I think I need to create variables, but I couldnt find how to. There is not so much info about variables and how to use.

I dont know Unity so much, maybe its something easy without using AC, I am open for every idea.

Can anyone help me?

Comments

  • ok I ve made this with help of a friend

    using UnityEngine;
    using System.Collections;

    public class RotationControl : MonoBehaviour {

        public GameObject go1;
        public GameObject go2;
        public GameObject go3;
        public GameObject go4;

        void Update()
        {
            if ((int)go1.transform.rotation.eulerAngles.y == 90 && (int)go2.transform.rotation.eulerAngles.y == 90 && (int)go2.transform.rotation.eulerAngles.y == 90 && (int)go4.transform.rotation.eulerAngles.y == 90)
            {
                Debug.Log("done");
            }
        }
    }

    But I am still wondering, if there is anyway in AC itself with variables.
  • Yes - it'll be a combination of Variables and a custom script (because of the very specific nature of your puzzle's solution).

    What you can do is create a Boolean variable that acts as a "solved" check.  The script will update this variable manually, and the Variable can then be used in Actions to act accordingly.

    First, create a Bool variable in the Variables Manager.  I'd suggest creating a Local variable, since these objects all appear in the same scene.  Rename it to RotationIsCorrect, set it's Initial value to False, and take a note of it's ID value (the number to the left of the colon in the list of buttons).  We'll use this number in the script.

    Adapting your supplied script, remove the Update function and replace with this:

    void CheckSolution ()
    {
      if (go1.transform.rotation.eulerAngles.y == 90f && go2.transform.rotation.eulerAngles.y == 90f && go2.transform.rotation.eulerAngles.y == 90f && go4.transform.rotation.eulerAngles.y == 90f)
      {
        LocalVariables.SetBooleanValue (1, true);
      }
      else
      {
        LocalVariables.SetBooleanValue (1, false);
      }
    }

    This sets the Local boolean of ID 1 (replace the 1 with your own ID number) to either true or false, depending on whether or not the puzzle is solved.

    When we want to see if the puzzle is solved or not, we need to call this function, and then use the Variable: Check Action to look at the boolean's state.

    To call this function, use the Object: Send message Action, set the Object to affect as the object with your custom script attached, and set the Message to send to Custom, and the Method name to CheckSolution.  This will cause our function to be called, and the local variable will be updated.

    Next, use the Variable: Check Action - setting the Source to Local will let you select your boolean from the popup box.  As for what happens if the solution is correct / false, it helps to view this actionlist within the ActionList Editor window, available from the top Unity toolbar under Adventure Creator -> Editors.
  • Thank you Chris, now I understand(I hope:)) how to use variables  I will try. 

    BUT; I've tried this(my friend's) script, but then there is a problem appear; when objects start to turn, they didnt turn excatly 90 degree(even I've said 90) every time they turn in different angle-but slightly different. Sometimes they turn 89,75.... sometimes 91,1234... but never excatly "90" Is it a bug? or something I am doing wrong?

    thank you very much
  • No problem, but please understand I can't really go and fix your friend's script! However, make sure that you rotate by floats, not integers. If the problem persists, just check the "nearby" rotation: e.g. >89, <91, instead of =90. Unity rotations are rarely exact, and ar
  • * and are generally off their intended value by a very small amount anyway.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.