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 /
This question was closed Sep 30, 2014 at 06:28 PM by Xain for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Xain · Sep 28, 2014 at 11:05 AM · axisrangey

Y Axis Limit

Hello everyone , i have a an object and i want to do limit to y axis im using javascript. How can i make it in 5-17 range ?

Thanks.

Comment
Add comment · Show 1
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 christoph_r · Sep 28, 2014 at 11:30 AM 0
Share

There's quite a few ways to do it, which one works best actually depends on how you access that object's y value. The easiest but least elegant way would be to have your upper and lower range limit and use $$anonymous$$athf.Clamp in Update. Another option would be using a property with a range attribute, and each time you change your object's y value you actually access that property, which handles setting the y value. This only works if you don't utilise physics, though.

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by christoph_r · Sep 28, 2014 at 05:19 PM

How about this?

    function Update ()
     {
     if (CFInput.GetKey(KeyCode.W) && transform.position.y <15)
     {
     rigidbody.velocity.y = speed;
     }
     else if (CFInput.GetKey(KeyCode.S) && transform.position.y > 7)
     {
     rigidbody.velocity.y = speed *-1;
     }
     else
     {
     rigidbody.velocity.y = 0;
     }
      
      
     }
 

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

Answer by robertbu · Sep 28, 2014 at 01:53 PM

If your object is only rotating on the 'y' axis, you can do:

 var euler = transform.eulerAngles;
 euler.y = Mathf.Clamp(euler.y, 5.0, 17.0);
 transform.eulerAngles = euler;


The problem is significantly more complicated if you are allowing rotation on multiple axes. I'd need to see your rotation code in order to advise.

Comment
Add comment · Show 1 · 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 Xain · Sep 28, 2014 at 05:05 PM 0
Share

Sorry but i don't want to rotate this object i just want to do limit to y direction this is my y speed code ;

 #pragma strict
 
 var moveUp : $$anonymous$$eyCode;
 var moveDown : $$anonymous$$eyCode;
 
 var speed : float = 5;
 
 function Update ()
 {
     if (CFInput.Get$$anonymous$$ey($$anonymous$$eyCode.W))
     {
         rigidbody.velocity.y = speed;
     }
     else if (CFInput.Get$$anonymous$$ey($$anonymous$$eyCode.S))
     {
         rigidbody.velocity.y = speed *-1;
     }
     else
     {
         rigidbody.velocity.y = 0;
     }
 
     
 }

Follow this Question

Answers Answers and Comments

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

Related Questions

Rotate and Move towards Mouse Point 0 Answers

How to lock the y axis in camera script? 2 Answers

LookAt without Y axis 2 Answers

Lock the Camera's Y Rotation Axis? 0 Answers

how do i Limit camera rotation on Y-Axis? 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