• 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 t$$anonymous$$s error with t$$anonymous$$s script. "NullReferenceException: Object reference not set to an instance of an object" T$$anonymous$$s is supposed to be in javascript... in case i did somet$$anonymous$$ng wrong, language-wise.

its somet$$anonymous$$ng 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 breat$$anonymous$$ngObj : GameObject;
 var hasSprinted : boolean = false;
 
 function Update () {
 
 if(breat$$anonymous$$ngObj.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(breat$$anonymous$$ngObj.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. mind 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 t$$anonymous$$ng as transform.Rotation. Capitalization is very important. Also, that won't work even when corrected, since transform.rotation is a quaternion, w$$anonymous$$ch 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 MouseLook script in the character controller standard package for an example of a script that uses its own variables to track rotation of specific axes instead 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 { MouseXAndY = 0, MouseX = 1, MouseY = 2 } public RotationAxes axes = RotationAxes.MouseXAndY; public float sensitivityX = 15F; public float sensitivityY = 15F;

public float minimumX = -360F; public float maximumX = 360F;

public float minimumY = -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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Is anyone able to fix my code? 3 Answers

Script gives wrong rotation. 1 Answer

An object reference is required for the non-static field, method, or property 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