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 MC HALO · Apr 30, 2011 at 11:49 PM · mathfclamp

Can someone explain this MouseMove script to me :)

Hi guys, i was wondering if you could explain something to me. I just made a script called mouse x basically its my own mouse move script :). But i came across a code that got me thinking why it is there and if i remove why it stops my rotation on the script. the script is here:

public enum RotationAxis {MouseX = 1} var RotationAxisX = RotationAxis.MouseX;

var sensitivityX : float = 400f;

public var minimumX : float = -360;

public var maximumX : float = 360;

public var rotationX : float = 0;

var OriginalRotation : Quaternion;

function start(){

OriginalRotation = transform.localRotation;

}

function Update () {

 if(RotationAxisX == RotationAxis.MouseX){

 rotationX += Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;

 rotationX = ClampAngle (rotationX, minimumX, maximumX);

 OriginalRotation = XQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);

 transform.localRotation = OriginalRotation * XQuaternion;


} }

function ClampAngle (angle, min , max ):float {

if(angle < -360f){ angle += 360; } if(angle >360){ angle -= 360;

} return Mathf.Clamp (angle,min, max); }

basically its the "Function ClampAngle " line that contains the code i am talking about. the code of line is

 return Mathf.Clamp (angle, min, max); 

this is the line of code that i am talking about if i delete this line of code it makes the x rotation completely stop and why is that :)

secondly i was wondering if someone can tell me what an Quaternion is :) thank you very much in advance :)

MCHALO

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
1
Best Answer

Answer by GesterX · May 01, 2011 at 12:23 AM

If you remove that line then your ClampAngle function does not return anything. You use this in the following line to set the X rotation:

rotationX = ClampAngle (rotationX, minimumX, maximumX);

If ClampAngle does not return anything then the X rotation is never updated.

A quaternion is a mathemetical model to represent a rotation in a compact way. They are extremely difficult to understand fully and it's easiest to learn what they do by experimenting or modifying existing code.

http://unity3d.com/support/documentation/ScriptReference/Quaternion.html

Comment
Add comment · Show 3 · 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 MC HALO · May 01, 2011 at 12:43 AM 0
Share

thank you very much that was help full you are great :)

avatar image GesterX · May 01, 2011 at 12:45 AM 1
Share

No worries dude. Glad I could help.

avatar image MC HALO · May 01, 2011 at 12:52 AM 0
Share

and thanks for the link :)

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

Mathf.Clamp() not working as expected. 4 Answers

A node in a childnode? 1 Answer

How do I find the inverse cosine ??? 1 Answer

Increase/reset speed on tilt 0 Answers

How do i Clamp the Z position of a rigidbody? 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