I am working in a situation where a character is moving around a board-game like level using a simple transform.translate - however, I don’t want the character to be able to move off of the edge of the level.
I want to do this by not allowing the character to never not be in contact with the collider of the level. Is there any good way for me to do this?
Or is there a way I can enact bounds to simply prevent the user from moving outside the level?
I’ve tried that. Doesn’t seem to want to work. I think it’s because I’m using transform.translate to move - so I effectively ‘teleport’ past the collider.
My issue is that I am essentially emulating a board game. The character moves a fixed distance from tile to tile. The way I found to move most easily was transform.translate. Is there a better way for me to move a fixed distance?
if (Input.GetKeyDown ("down")){
if (bounds.Contains(controller.center + new Vector3(0,0,-speed))){
transform.Translate(Vector3(0, 0, -speed), controller.transform);}
}
What behavior is that script giving you? What does bounds represent in this situation since it does not specifically reference an object? The bounds of the Mesh, the Renderer, or the Collider? It seems like you would want to get the bounds of the level by having a variable to hold a reference for the level and get the bounds from that.