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 88bueno · Aug 24, 2010 at 03:57 PM · axislimitationsrestrictmovement

restricting movement along an axis

I'm relatively new at programming, and find that Java is the simplest for me. I'm looking to keep a game object within a certain field of movement to stay inside the view of the camera without messing with a lot of barrier planes. I set the movement with the mouse, and set the requirements within the if statement to be that the position has to be between X.X on the X-axis and X.X on the Y-axis. This is successful but when it hits the edge it no longer lets me move the object in-game. Anyone got a fix?

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 PeterDC · Sep 27, 2010 at 12:20 PM 0
Share

Unity uses Javascript, not Java; they're two different program$$anonymous$$g languages.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Loius · Oct 12, 2010 at 02:22 AM

You can use

x = Mathf.Clamp( x, 0.0, 5.0 );

If x is below 0.0, it will be set to 0.0; above 5.0, will be set to 5.0; otherwise, it's unchanged.

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 BurningThumb · Aug 28, 2010 at 03:25 AM

I assume your logic that states that you can only move if you are within the bounds specified, when you reach them your script probably disables the ability to move because you've told the program to do that. You really should just use collisions, thats what they are there for.

If your implementation looks like this :

if (inBounds)
    {
    mouvement logic;
    }
    else
    {
    return;
    }

Try this instead

if (inBounds)
        {
        mouvement logic;
        }
        else
        {
        move player back into bounds;
        }

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 88bueno · Aug 28, 2010 at 07:51 PM 0
Share

so I should just use planes and dde-render them but put colliders on them? Is that what you're saying? Like, the code is an alternative to colliders?

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

Restricting axis of movement not working at all! 1 Answer

How can I get the distance from point a to point b on a custom axis? (Includes pictures) 1 Answer

Problem with input code for a camera follow/rotate script 0 Answers

Rotating a player object without rotating the axis 0 Answers

calculating my position from another object 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