- Home /
How To Make An Invisible Wall That's Impossible To Get Out Of?
Hello once again awesome people of Unity answers. I have a question that's out of wanting to do it, and curiosity. You see, I want to make an invisible wall that my Player cannot pass through no matter what, but I don't know an effective way of doing that. So far, I use an invisible box collider 2D, and for the most part it seems to do the job. However, recently I've been able to glitch through it and while it doesn't break the game, it does cause me to die. I would just like to avoid dying like that you see. Anyways my box collider 2D isn't really that big, but could that be the reason why I can glitch through it? Or is it another reason? By the way, I'm not the only one who can glitch through box colliders. My Ai can also do it. As a matter of fact it does it all the time. So what can I do? I would love to hear anyone's thoughts/advice.
Hi, do you $$anonymous$$d providing some more info? I'm currently assu$$anonymous$$g you're using a 2D character. Is that true? If so, you should clamp it's position. EDIT: Oh and is your character moving at a really fast speed? If it is, that may be the cause.
I don't $$anonymous$$d at all. Yes I'm using a 2D character. $$anonymous$$y character does move at high speeds when he goes through the collider. It's like a glitch when I jump, after I jump off a object, my Player blasts off up and goes through the invisible collider. This doesn't happen all the time, but it's a problem that I know needs to be sorted. As for my Ai, it does move at a pretty decent speed too. Oh and sorry for this noob question I'm about to ask, but how exactly does one clamp the character's position?
It doesn't matter if you're a noob, everyone is here to help or gain knowledge. What plane does your character move on? X axis? Or is it top-down?
EDIT: Here's a link about clamping: http://docs.unity3d.com/ScriptReference/$$anonymous$$athf.Clamp.html
He moves on the X-axis. Left to right. He jumps up, and then falls down. The collider that's he glitches through is on the top, like a ceiling.
Here's what you can try: transform.position = new Vector3(transform.position.x, $$anonymous$$athf.Clamp(transform.position, floorY, ceilingY), transform.position.z);
(Note: Untested code, written without the use of an IDE)
Answer by Kiwasi · Oct 10, 2014 at 03:12 AM
Fast moving objects and thin colliders is a well know issue. Some options to consider
Slowing down
Thicker colliders
Changing the collision mode on the RigidBody
Ignoring physics and using scripts to constrain position
Reducing the physics time step
Edit: Added further solutions from comments.
So thicker colliders do make a difference? That's what I'm currently trying, so far I haven't been able to run into the glitch, but when I do we'll see if it works.
Thicker colliders do make a difference. The glitch is caused by a fast moving rigidbody 'jumping' over a thin collider between physics updates. The thicker your colliders, the faster an object has to be moving for a jump to occur.
Which brings me to another method to solve the problem
Reducing the physics time step.
"Reducing the physics time step". Okay I think I know what you mean. I'll see what I can do by messing around with it. Thanks for your help.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
GetComponent().enabled = true; 1 Answer
How To Add PlayerPrefs Scores? 1 Answer
Make player not be seen by AI, when player in foilage and shadows. 1 Answer
Starting out C# help 2 Answers