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 PaxStyle · Apr 05, 2014 at 10:50 AM · animationrotaion

Add max Angle to rotation.

Hi, how can i add the max rotation angle to this script?

 #pragma strict
 
 var amount = 5.0;
 
     
     
     
 function Awake ()
 {
  
 }
 
 
     
 function FixedUpdate()
 {
    if (Input.GetKey(KeyCode.A)) {
       rigidbody.AddForce(transform.right * amount);
    }
    else if (Input.GetKey(KeyCode.D)) {
       rigidbody.AddForce(-transform.right * amount);
    }
    else if (Input.GetKey(KeyCode.S)) {
       rigidbody.velocity = rigidbody.velocity * 0.9;
    }
    
    
    
 }
Comment
Add comment · Show 7
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 PaxStyle · Apr 05, 2014 at 05:24 PM 0
Share

ehy someone can help me?

avatar image PaxStyle · Apr 06, 2014 at 08:36 AM 0
Share

please :(...

avatar image deltamish · Apr 06, 2014 at 09:24 AM 0
Share

by maximum rotation angle do you mean to restrict the object rotation to certain amount or the instantiated object

avatar image PaxStyle · Apr 06, 2014 at 02:58 PM 0
Share

restrict the object rotation to certain amount

avatar image PaxStyle · Apr 06, 2014 at 06:48 PM 0
Share

any help is good

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by deltamish · Apr 07, 2014 at 11:54 AM

Hi Inorder for you to restrict an objects rotation you need to know some basics about Vectors and how Unity sees it

and is the object rotates manually from this script or another script ?

here is an simple script that restricts the object rotation on its Z axis with respect to its forward vector at start

 public var MaxAngle:float = 180f;
 
 
 private var CurrentAngle:float =0;
 
 Vector3 ForwardVector;
 Quaternion rotation;
 
 function Start()
 {
  ForwardVector = transform.forward;
 }

 function Update()

{

}

 function LateUpdate()
 {

  
   CurrentAngle = Vector3.Angle(ForwardVector,transform.forward);
     
      if(CurrentAngle <= MaxAnlge)
        rotation = transform.rotation; //update the changs only if angle is less than max
     
       transform.rotation.x = rotation.x;    // set rotation on x axis (which maske the object rotate forward)      
     
      
     }

Note : this is an simple script that restricts the angle on zaxis only if you want it on other axis then you have to write another code or just write the same code for different axis as well .If want any help please ask

Comment
Add comment · Show 5 · 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 PaxStyle · Apr 07, 2014 at 04:32 PM 0
Share

sorry but before i don't sow this.. the code that i've posted works with a hinge joint, is your code also good?

avatar image PaxStyle · Apr 08, 2014 at 05:39 PM 0
Share

your script it's all wrong

avatar image deltamish · Apr 09, 2014 at 04:23 PM 0
Share

what is wrong waht is happening.I havent tested it yet.

Once again is the rotation due to this or other object

avatar image PaxStyle · Apr 09, 2014 at 04:52 PM 0
Share

I added your script to my, but unity give me errors, so i cannot try it if works.

avatar image deltamish · Apr 15, 2014 at 03:11 PM 0
Share

whst errors can you please post them

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Can I make animations snap to a frame? 1 Answer

How to select an animation clip by index number? 7 Answers

How much money would it take to have some one animate something for me? 0 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