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 AlecSH01 · Aug 07, 2013 at 05:15 PM · map

How to keep players from falling off the map

Hi, I have a problem... Whenever I am testing my game I can just walk off the map... How do I fix this? 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 AlucardJay · Aug 07, 2013 at 09:53 PM 0
Share

Clamp the position of the player :

  • http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$athf.Clamp.html

  • http://www.youtube.com/watch?v=eUcqd89OiSc

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TheRichardGamer · Aug 07, 2013 at 05:16 PM

Try making invincible walls, most games use invincible walls to prevent things like that.

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 creighcl · Aug 07, 2013 at 05:48 PM

If you're using the physics engine, you can create an empty gameobject and attach a Rigidbody and a Collider.

Just expand that collider to create an invisible wall that cannot be passed through.

If it's not a physics based game, you'll have to get a little more creative based on how you have setup your movement.

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 hukondejo · Jun 26, 2017 at 02:13 PM

 var groundLimit : int;
 var XOrigin : int;
 var ZOrigin : int;
 var height : int;
 
 if (height < 0){
 print("FALLPREVENT:Height must be more than 0.");
 height = 0;
 print("FALLPREVENT:Setting height to 0.");
 }
 else
 {
 transform.position = Vector3(XOrigin,height,ZOrigin);
 }
 function Update () 
 {
 if (transform.position.y < groundLimit){
 
    transform.position = Vector3(XOrigin,height,ZOrigin);
 }
     
 }

When you begin falling this respawns you in the given coordinates. You can set the following values.:

Ground Limit - if You reach this height limit you will respawn. must be a negative value. Height - your height position after respawn. must be a positive value. X and Z origin - your position after respawn.

Note : The given coordinates will be your ingame starting point. You can attach it to any gameobject what uses gravity.

Comment
Add comment · Show 2 · 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 Linkthehylian04 · Jun 26, 2017 at 02:30 PM 0
Share

This person might not use javascript. You should keep a c# version on hand.

avatar image hukondejo · Oct 12, 2017 at 07:44 PM 0
Share

Here is an updated version of of the script. Its in c# and it grabs any needed value from the gameobject automaticaly. Attach it to any gameobject what uses gravity.

 public class FallPrevent : $$anonymous$$onoBehaviour
 {
 
     // Attach this script as a component to the character
     private float Xorigin;
     private float Zorigin;
     private float Height;
    
     private void Awake()
     {
         // Setting Startpoint
         Xorigin = transform.position.x;
         Zorigin = transform.position.z;
         Height = transform.position.y;
         // Asking Height
         if (Height < 0)
         {
             print("FALLPREVENT: Height is bellow zero! Setting secure height.");
             Height += 3;
         }
     }
     void Update ()
     {
         // Character respawns to the starting point when falling.
         if (transform.position.y < 0)
         {
             transform.position = new Vector3(Xorigin, Height, Zorigin);
         }
         
     }
 }

avatar image
0

Answer by Linkthehylian04 · Jun 26, 2017 at 02:32 PM

Create an empty GameObject, name it "Wall", give it a box collider, then use it as an invisible wall so that you can't fall off the edge.

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

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

19 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

Related Questions

In Game Animation problem 0 Answers

Assigning UV Map to model at runtime 0 Answers

First Person controller problem 1 Answer

I need help knowing if Im doin this Right 1 Answer

Normal map appears to be wrong when generated 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