- Home /
Character Controller slides sideways when it hits objects are angles different from 90 degrees
Hi there I'm new to Unity and new to UnityAnswers. I have a programming background so I'm doing all my scripting in C#. I have an issue with my character controller. The Script for the movement I have basically makes my character move on a fixed path around a circumference with center (0,0,0). That works fine, except when there is an obstacle in the way, where I want the character to stop when it collides with it. Lets say my character hits a wall in the path, instead of stopping, it's sliding sideways through the wall. It only stops at the wall if the angle between the character and the wall is 90. This has nothing to do with the slope. The character is NOT climbing the wall, is walking side ways, to the left or right depending on the angle.
What I'm doing to move my character is add some speed to the forward vector of the character and then rotate it according to the angle in the circumference, then do the same next update.
Could anybody help me figure out what am I missing? Thanks Joe
Answer by Bunny83 · Jun 20, 2011 at 04:34 PM
That sounds to me like the normal collision response. If you walk up to a wall in an narrow angle you don't want to stop the motion when you touch the wall. The speed gets projected along the wall. If you hit the wall at a right angle the projected speed will be "0" of course.
If you want to stop the motion you should stop moving the character forward when you collided with a wall.
Hi, thanks for the response. I noticed in another sample that's the expected behavior, I was looking for a way of limiting this projection without having to check for a collider. I'm trying to $$anonymous$$imize the checks I have in my physics controller since I intend this to run on iPhone 3G and so far the performance is not so good. I thought that a possible solution could be on collision to update the character rotation against the collider's normal. That however could misbehave when the character get's trapped between two walls or similar situations. What do you think?
Well, the collision will happen anyway, so your solution sounds quite similar :D. You could of course rotate the character that it looks along the negative hit normal, but if you continue moving forward you will collide every frame and therefore OnControllerColliderHit will be executed every frame.
I don't know your setup. Does the objects you collide with are moving? It should be possible to place a trigger in front of your objects (maybe it works as well when you add a trigger to your character). If you get the OnTriggerEnter event you should stop moving forward and when OnTriggerExit occurs you can continue moving.
That actually sounds better. I'll try that later today and I'll let you know how it goes. Thanks!
Your answer
Follow this Question
Related Questions
Click to Move rotation + collider issue 0 Answers
OnCollisionEnter 1 Answer
Player model rotates forward with camera 0 Answers
How to change the angle my character falls at 1 Answer
Why can't I properly jump? 2 Answers