• 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 rataius · Jul 01, 2012 at 08:51 PM · positionplayerjavalimits

How to set limits to where player can go

Hi. I am not good at this but I hope you can understand what I am asking. I am trying to set up a script that is equipped to my player object(currently this is the default 3rd person controller) and I have myself a primitive town built*plan to create most of the models in blender* and I have it set up so that the player can roam freely around the terrain of the town. What I need though is a way to set up an invisable collision box type thing so that the player cannot go past a certain point.

I am trying to use a simple x1,x2,z1,z2 setup stating that if the player goes past x1 the player is stuck there and can't go further. This is what I was thinking it should look like say x1 = -85, x2 = 85, z1 = -75, z2 = 75

now if the player goes past x1 they are stuck at -85 on the x axis and so on.

So how can I set this up. keep in mind I am using Java in Unity. I am most comfortable with it.

I'm sure I could use Geometry to do this but I am trying to avoid using geometry as it can look really fake when the player touches the wall.

I hope this makes sense and I hope someone can point me in the right direction.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Piflik · Jul 01, 2012 at 08:53 PM

For invisible walls I would simply create an Empty in the scene and add a collider to it. You can surely also do it with scripts, but that would be very complicated, depending on the complexity of your terrain.

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 tomekkie2 · Jul 01, 2012 at 08:55 PM

Just put a meshcollider object with no renderer attached to block the player from entering where he is not supposed to enter. The player then would be able to cross one way only - into the inside along the normal and would be blocked to the outside which is against the normal.

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 rataius · Jul 01, 2012 at 09:45 PM

I figured it out guys. I was hopeing I could delete this before someone answered. I used the respawn method. the script looks like this now.

 //This will keep the player from going past a certain point. Think of it as a collision box without geometry
 
 function Update () {    
     var myPosX = transform.position.x;        
     var myPosZ = transform.position.z;        
     Debug.Log("x: " + myPosX + " / z: " + myPosZ);
     
     if(myPosX <= -85){
         transform.position.x =-85;
     }
 }

So I am sorry for wasting your precious time guys. Thanks for the help though.

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 christian.jung · Mar 02, 2013 at 10:22 PM

what would i do if i had a paddle and it went through the floors.

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 RencendStudios · Feb 23, 2017 at 11:39 PM 0
Share

Does the paddle have an attached collider?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

(Roll a ball) The camera for the ball doesn't follow the ball. 2 Answers

How to lock the players position by Z? 3 Answers

Particles to not be affected by main camera? 0 Answers

How to keep position on input.get axis even when it is pressed twice? 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