- Home /
simple collision not working
I feel stupid to have to ask for help on this.
I have a player object with a capsule collider (I don't want to use the character controller because I don't want gravity). I also added a RigidBody component and marked it as Kinematic and turned off gravity.
I have other static objects in my scene with primitive colliders but no rigidbody.
When I move my player I want it to collide with the static objects and NOT PASS THROUGH. I'd like it to slide around the colliders it runs into, like you would expect a player to do when colliding with something at an angle.
I don't really care about the collision events at this time, I only want to prevent the player from walking through stuff. What am I missing?
Answer by syclamoth · Oct 09, 2011 at 08:32 AM
You need to have a non-kinematic rigidbody to enable physics of any kind! A kinematic rigidbody will not bounce off of other objects, because it is assumed that it is not being moved in any physical way. If you are moving your object just using transform.Translate or related methods, it will never interact with other colliders unless there is also a non-kinematic rigidbody on the same object (in which case you shouldn't be using transform.Translate anyway). If you don't want gravity, you can just turn off 'useGravity' on your rigidbody, or in a more general way, you can set 'Gravity' to (0, 0, 0) in the physics settings to create a zero-gravity environment.
Also- in what way do Character Controllers have gravity? You have to manually code that in! (It's part of what annoys me about them...)
I realized that there are a couple of problems.
1) I have to use rigidbody.$$anonymous$$ovePosition() and .$$anonymous$$oveRotation() to manually move my rigidbody, ins$$anonymous$$d of the normal transform.position, etc.
2) Apparently I don't understand the full meaning of "kinematic" because I understood it to mean that the rigidbody would be manually controlled ins$$anonymous$$d of controlled by physics. This would be my character - manually controlled. When I have kinematic enabled, my character won't move at all using the rigidbody.$$anonymous$$ovePosition() method. I have to disabled it when moving him, then re-enable it when he stops, otherwise he'll float off into space after bouncing off obstacles. This seems odd to me.
To answer your question about Character Controllers and gravity, I was looking at the docs for "Simple$$anonymous$$ove", which says "Gravity is automatically applied." I see now that it doesn't apply to plain 'ol "$$anonymous$$ove". $$anonymous$$aybe the CharacterController will work for me after all, but I don't see a method for setting the rotation.
You just use Transform.rotation to rotate CharacterControllers.
you can use freeze location under the rigidbody settings to have it still be kinematic & only controlled through code
Your answer
Follow this Question
Related Questions
Parent Object 0 Answers
Advice for Intersecting Colliders 0 Answers
My character falls over when colliding 1 Answer
Problem with collision - Collision.other.gameObject is obsolete 1 Answer
Maintain velocity after impact with kinematic rigidbody 1 Answer