• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Joe 24 · Jun 20, 2011 at 02:06 PM · rotationmovementcollidercharactercontrollerpath

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Joe 24 · Jun 20, 2011 at 05:11 PM 0
Share

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 minimize 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?

avatar image Bunny83 · Jun 20, 2011 at 05:25 PM 0
Share

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.

avatar image Joe 24 · Jun 20, 2011 at 05:31 PM 0
Share

That actually sounds better. I'll try that later today and I'll let you know how it goes. Thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

AI Character not rotating when spawned in 0 Answers

How do i rotate based on direction character is moving in 1 Answer

How can I move a character to a point in a straight line with CharacterController.Move while rotating him? 2 Answers

Why can't I properly jump? 2 Answers

How to Logically Match Ground Slope While Using This Code? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges