- Home /
Prevent items/player from going through walls/floor
There's this online game, Asheron's Call, I'm not sure if I can say the name of it here (??) so sorry if not. Basicaly no matter how hard you try, you can't go through the walls, you can't glitch through or anything and I was wondering if there's a way to make a Unity3d game like that? AC works with "landblocks" and if your character runs into a landblock area that's missing or crashed then you lag out and disconnect, and the game can't save your character there so it reloads you back where it last saved you, although this was a problem in AC before, because it allowed duplicating of items when abused, I still liked that you couldn't fall through walls or the floor no matter how hard you tried. In Unity3d you'd fall forever unless there's a fallout script.
I understand they used a different engine, but just curious if something similar is possible in Unity. I'd like to prevent the possibility of falling through, no matter the velocity, size, gravity, or mass of the object.
maybe a script even, like a fallout script but instead of a total reset or death it detects the character/object going through the floor and sets to nearest x,y,z above terrain/within gaming boundaries. that way as soon as the object even thinks about going through, it's instantly reset to the correct side of the wall/floor
I am no good at scripting yet so let me know :)
You need to start searching for yourself before you ask new questions. Preventing fall-through is really common, and it took me like 20 seconds on google to find 4 links:
http://answers.unity3d.com/questions/34806/triggers-and-going-through-objects.html
http://answers.unity3d.com/questions/17586/prevent-object-from-passing-through-collider.html
http://forum.unity3d.com/threads/56221-physics-objects-passing-through-moving-floor
http://answers.unity3d.com/questions/8207/charactercontroller-falls-through-or-slips-off-mov.html
Thanks, I did google, and I did search, and I came up with pretty much what you did. It's not the information I'm looking for.
Answer by save · Oct 10, 2011 at 09:28 AM
I'd update a Vector3 variable once a second or so when the player is grounded.
var currentGroundPos : Vector3;
function Start () { InvokeRepeating("CheckPos", 0, 1); }
function CheckPos () { if (grounded) { currentGroundPos = transform.position; } }
To check if something is grounded you can either use the CharacterController variable isGrounded, collision detection or use a raycast, have a look at Aldonaletto's answer.
When the player falls below the ground you relocate the player, which would be like this for an example:
var player : GameObject;
var lowestGround : int = -10;
if (player.tranform.position.y < lowestGround) {
player.transform.position = currentGroundPos;
}
Using this method you could also check if the player is grounded before you save your game.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How can I set the order of destruction of game objects? 1 Answer
Script for Vanishing Platforms 2 Answers
How to import the object from server to unity 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers