Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working on a 3D Platformer in Unity3D and I need to prevent the player from going through walls. The movement for my player works like this:

bird-eye-view player movement

(A bird-eye-view representation)The areas the player can move a divided into layers. He can slide into the 2nd, 1st , or 3rd layers. The player is not a rigid-body, and is controlled using a character controller. To move the player into these layers I simply increase his Z-Axis. Currently if my player is behind the wall he will slide directly into it. How can I determine if there is a wall to the left of the player in Unity 3D? If so, I simply wont allow the user to move to the layer until they have steered clear of the obstacle. Does anyone have any suggestions of what I should do?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You can use function CharacterController.Move to detect collision to the wall. if you don't want to use Move then you can cast a ray with Raycast to check if wall close enough to stop your character or let him move ;)

share|improve this answer
    
Thanks. I ended up going with CharacterController.Move function MoveTo(newPos : Vector3, controller : CharacterController) : IEnumerator { vertMoveDirection = newPos - transform.position; controller.Move(vertMoveDirection); } However I want the movement to be smooth. Is there anyway I can do this in this function? –  Grey May 25 '13 at 22:19
    
what's wrong with movement ? –  Artyom May 25 '13 at 22:50
    
It sort of teleports. Anyway I'll figure it out :) –  Grey May 25 '13 at 23:20
1  
Vector3.lerp could help ;) –  Artyom May 25 '13 at 23:25
    
Ended up using raycasting =) –  Grey May 26 '13 at 14:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.