- Home /
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.
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.
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.
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.
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.
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
Call Other Object to Self 2 Answers
Changing player's moving direction 0 Answers