Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Shanderia · May 24, 2011 at 06:19 AM · movementlevelboundaryrestrict

Restrict character's movement within a level's map

Hi everyone !

I'm making a level and using a First Person Controller as my character. However, I want to limit my character's movement within the level boundary, which is a plane. I don't want him to go beyond the limit and fall from there, I just want him to be stopped there by an invisible wall. Is there anyone who can help me with this problem ? Thank you in advance !

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
2

Answer by Max 4 · May 24, 2011 at 06:52 AM

There are a few ways to do this. Firstly, you could add a box collider to an empty game object, and stretch that however you like. Then there are more complicated ones, like this:

     transform.position.x=Mathf.Clamp(transform.position.x,0, 100);
     transform.position.z=Mathf.Clamp(transform.position.z,0, 100);


There are many more ways in between, as well however.

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 Shanderia · May 25, 2011 at 10:05 AM 0
Share

Is there any way which is considered better than others ? If not, I think I will just stick with the method which creates "invisible walls" since it seems to be the simplest way to me. Thank you very much !

avatar image leonalchemist · Sep 22, 2011 at 04:17 PM 0
Share

can anyone tell me when i use this code on the player when i reach those restrictions the camera shakes as if the player tries to go past that limit.

part of the player's movement code is like this:

var y$$anonymous$$ove : float = Input.GetAxis("Vertical") Time.deltaTime PlayerSpeed; transform.Translate(Vector3(0,y$$anonymous$$ove,0));

just basic code so anyone knows why this happens?

avatar image teomaragakis · Apr 17, 2014 at 07:23 PM 0
Share

@leonalchemist Does the player have a rigidbody? If so, Click freeze rotation in all axes.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Restric the script and movement in specific area 0 Answers

How to keep an object within a circle/sphere (radius) - NO RECTANGLE 3 Answers

How can I restrict player movement to the edges of the plane so that they don't fall off the platform? 2 Answers

Restrict player movement to circle's circumference and rotate to lookat 4 Answers

The name 'Joystick' does not denote a valid type ('not found') 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