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 DNP · Aug 05, 2012 at 12:29 AM · rotation

What is wrong with this script?

i keep getting this error with this script. "NullReferenceException: Object reference not set to an instance of an object" This is supposed to be in javascript... in case i did something wrong, language-wise.

its something with the "if(lightObject.transform.Rotation.x > 31){" but i dont know what im doing wrong.

Please help!

Heres the code:

 var lightObject : GameObject;
 var breathingObj : GameObject;
 var hasSprinted : boolean = false;
 
 function Update () {
 
 if(breathingObj.GetComponent(SprintScript).isSprinting == true){
 
  lightObject.transform.Rotate(Time.deltaTime * 50, 0, 0);
  
  hasSprinted = true;
 
  if(lightObject.transform.Rotation.x > 31){
  
  lightObject.transform.Rotation.x = 31;
  
  hasSprinted = true;
  
  }
  }
  
 else if(breathingObj.GetComponent(SprintScript).isSprinting == false && hasSprinted == true){
 
  lightObject.transform.Rotate(Time.deltaTime * -50, 0, 0);
  
  if(lightObject.transform.Rotation.x > 0){
  
  lightObject.transform.Rotation.x = 0;
  }
  }
 }
Comment
Add comment · Show 2
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
avatar image slayer29179 · Aug 05, 2012 at 12:35 AM 0
Share

I am not too sure about rotation my self but when using it I try; Rotation.x rotation.x rotate.x Rotate.x Vector3.right maybe that may help you?

avatar image DNP · Aug 05, 2012 at 12:37 AM 0
Share

Um, im not sure what you mean. $$anonymous$$d posting the changed code to what your saying? it would help me understand what you mean.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Eric5h5 · Aug 05, 2012 at 12:56 AM

There's no such thing as transform.Rotation. Capitalization is very important. Also, that won't work even when corrected, since transform.rotation is a quaternion, which is a 4-dimensional representation of an object's rotation, so rotation.x doesn't correspond to the x axis and is not in degrees anyway. Since reading one component from eulerAngles tends to be unreliable (since there's more than one valid way to represent an object's rotation), you're better off tracking the rotation yourself in a separate variable.

Comment
Add comment · Show 12 · 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
avatar image DNP · Aug 05, 2012 at 12:59 AM 0
Share

What would the variable represent?? would it be lightObject.localRotation?

avatar image Eric5h5 · Aug 05, 2012 at 01:03 AM 1
Share

No, localRotation is also a quaternion. The variable would represent the rotation in degrees; see the $$anonymous$$ouseLook script in the character controller standard package for an example of a script that uses its own variables to track rotation of specific axes ins$$anonymous$$d of trying to read it from the object (which is fairly problematic).

avatar image DNP · Aug 05, 2012 at 01:15 AM 0
Share

Alright. I see what you mean. But could you post an example? or if your bored perhaps a fix? becuase it will help me understand what you mean. Also, in the mouse look script, im guessing you mean these variables.

public enum RotationAxes { $$anonymous$$ouseXAndY = 0, $$anonymous$$ouseX = 1, $$anonymous$$ouseY = 2 } public RotationAxes axes = RotationAxes.$$anonymous$$ouseXAndY; public float sensitivityX = 15F; public float sensitivityY = 15F;

public float $$anonymous$$imumX = -360F; public float maximumX = 360F;

public float $$anonymous$$imumY = -60F; public float maximumY = 60F;

float rotationY = 0F;

avatar image Eric5h5 · Aug 05, 2012 at 01:27 AM 0
Share

I'm referring to the rotationY variable.

avatar image DNP · Aug 05, 2012 at 03:12 AM 0
Share

Why does it have an "F" next to the value???

Show more comments
avatar image
0

Answer by slayer29179 · Aug 05, 2012 at 12:41 AM

Sure :) Try These;

 if(lightObject.transform.Rotation.x > 31){
 
 if(lightObject.transform.rotation.x > 31){
 
 if(lightObject.transform.Rotate.x > 31){
 
 if(lightObject.transform.rotate.x > 31){
 
 if(lightObject.transform.Vector3.right > 31){

and see if they work :)

Comment
Add comment · Show 4 · 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
avatar image DNP · Aug 05, 2012 at 12:48 AM 0
Share

The second one works! thank you!

avatar image slayer29179 · Aug 05, 2012 at 12:52 AM 0
Share

Woohoo ^^ my first accepted answer :D thank you ! :D

avatar image DNP · Aug 05, 2012 at 12:53 AM 0
Share

no problem :3

avatar image Eric5h5 · Aug 05, 2012 at 12:57 AM 0
Share

Actually none of those is correct, sorry...see my answer for an explanation.

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

C# Unity 3D Lock Rotation but allow Rotation of Parent Object 1 Answer

qrest system 1 Answer

Help with movement script 2 Answers

Temporary Rotation 2 Answers


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