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 14, 2013 at 01:08 AM by gamerant for the following reason:

The question is answered, right answer was accepted in the coments

avatar image
0
Question by gamerant · Sep 02, 2013 at 07:55 PM · javascriptconstrain

How to limit movement along an axis?

Hi there,

I guess lets get straight down to business and let me explain the question since phrasing it correctly would of made it way too long. :P

I wrote a script that handles a platforms movement only along a single axis.Lets say the x-axis for the sake of argument.Now I've been trying to further constrain this movement only along the positive x-axis so that doesn't matter which way the world has been rotated (the game involves rotatable enviornment) the platform will always move in the same direction.

I tried using Mathf.Clamp but that hasn't solved the issue.did not work. If you are wondering what the script looks like then you can check it here where I posted it after solving a different problem that I had with it.http://answers.unity3d.com/questions/515128/fixing-the-nullreferenceexception.html

Just to clarify in case it's still unclear.I'd like to add a few changes to my script that would make the platform ignore the negative x-axis and move only along the positive x-axis.

Any tips and advice are welcome.

Cheers(Thank you) in advance.

Comment
Add comment · Show 4
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 Gjallanhorn · Sep 04, 2013 at 08:39 PM 1
Share

You mean this:

 if(destinationPos < targetPos && transform.position.z >= 0)
     {
        transform.position.z -= moveSpeed * Time.deltaTime;
  
     }else if(targetPos == targetPos)
     {
        onPlatform = false;
     }
avatar image FrimaMickD · Sep 04, 2013 at 08:43 PM 0
Share

Also, on the Rigidbody Component, you have a Constraints section where you can block the position and rotation on an axis. Unfortunately it will block all the axis not only positive/negative. Gjallanhorn answer would work for whta you want (or if your object do not have a rigidbody).

avatar image GC1983 · Sep 04, 2013 at 09:00 PM 0
Share

This is something I used. It limits the camera from moving up and down with the player when jumping or standing on higher platforms. You can use something like this, just make the axis you want to keep static as a set float and the others assigned to the players position.

 public void Update()
         {
             if(!isDead)
             {
                 if(playerObject.transform.position.x < mainCamera.transform.position.x)
                     camera$$anonymous$$ove = true;
             }
             
             if(!staticRoom)
             {
                 //true, follow player
                 if(camera$$anonymous$$ove)
                     mainCamera.transform.position = new Vector3(playerObject.transform.position.x - .1f, 
                         4.5f, mainCamera.transform.position.z);    
             }
         }
avatar image gamerant · Sep 05, 2013 at 02:54 PM 0
Share

@Gjallanhorn $$anonymous$$ind of silly of me to miss something like that but thank you. Did the job nicely.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

"Compilation Not Complete" keeps me from using my scripts. 0 Answers

Sequence of function Calls 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