Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Nik · Mar 01, 2011 at 11:20 AM · globalvariablesstatic-variables

Triggering Quaternion.Slerp from static variables of another script - strange phenomena?

Hi guys,

I am encountering a strange phenomena and I hope to seek some experts advices here.

Keeping the long story short, I have three scripts, a ScriptA for GUI and in which a button, where upon pressed on, changed a static variable "ChangeCameraAngle" (as boolean and originally set to FALSE) in ScriptB, and one more ScriptC that will based on the changed "ChangeCameraAngle" and start a Quaternion.Slerp and a Vector3.Slerp on the camera from its initial rotation, say (45, 0, 0), and its initial transform, say (100, 100, 100), respectively. All these scripts are attached to the GameObject 'Camera'.

First, ScriptB is just defining static variables (among others but I am leaving them out here):

static var ChangeCameraAngle : boolean = false;

ScriptA goes like this (leaving out other non-related lines):

function OnGUI () {

if (GUI.Button (Rect (0, 0, 150, 40), "ROTATE CAMERA")) { ScriptB.ChangeCameraAngle = true; }

ScriptC goes like this (leaving out other non-related lines):

function Update () {
   ....
   if (ScriptB.ChangeCameraAngle == true) {
      var NewRotation = Quaternion.Euler(0, 0, 0);
      var NewPosition = Vector3(0, 0, 0);
      transform.localRotation = Quaternion.Slerp (transform.localRotation, NewRotation, Time.time * 0.01);
      transform.localPosition = Vector3.Slerp (transform.localPosition, NewPosition, Time.time * 0.01);
   }
}

The Vector3.Slerp worked as intended, in that the camera moved from (100, 100, 100) to (0, 0, 0) when 'triggered' by "ScriptB.ChangeCameraAngle == true". But not so for the Quaternion.Slerp. The camera's angle jumped straight from (45, 0, 0) to (0, 0, 0), as if time.Time has no effect, despite I tried with a very small value of "time.Time * 0.0000001" too.

Now, the strange phenomena is that, for diagnosis purposes, IF I deliberately add another boolean variable in ScriptA or ScriptC to 'link' to "ScriptB.ChangeCameraAngle", so that I trigger a manual change of "ScriptB.ChangeCameraAngle" via the Inspector during play, the Quaternion.Slerp in ScriptB works according.

The additional "manual trigger" in ScriptA or ScriptC is just simply this:

var ManualTrigger : boolean = false;

function Update () { .... if (ManualTrigger == true) { ScriptB.ChangeCameraAngle = true; } }

So now I am at a loss, not exactly sure what was wrong with the original scripts. Would some kind souls out there please advise me? Many Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nik · Mar 01, 2011 at 04:14 PM

Hi all,

I like to "retract" this question. It turns out there is nothing wrong with these lines at all. I was able to narrow down the root cause to being another line that I had within the ScriptA's If-GUI.Button lines that enables another ScriptD (after setting ScriptB.ChangeCameraAngle = true), in which there is ANOTHER transform.localRotation that limited the angle x to zero. Hence ScriptA and ScriptD are being triggered at the same time, creating an situation where the Camera's angle x jumped straight to 0 based on ScriptD, and ScriptC having no chances at all to execute Quaternion.Slerp.

Thus it was all my own logic error in this case, and my apologies to those who may have been confused by me! Thanks.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Which object reference is not set to an object instance? 0 Answers

If Statements with PlayerPrefs 1 Answer

How can you save and update data between scenes and upon log in? 1 Answer

Csharp has no true global variable? 4 Answers

Using multiple instances of the same script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges