- Home /
Collision of a moving object with a standard 3rd person controller
Hello there,
I had an issue while working on a game and if you could point me on to the right direction it would be great!
I am trying to check collision between a horizontal cylinder which is rotating on the y-axis, with my 3rd person character(standard controller provided with Unity) controller that comes along with unity 3. Both my GameObjects have been assigned a rigid body component but somehow as soon as the cylinder comes close to the character it passes through it rather than colliding with it. Are there any particular settings i need to change to get this working? Your help on this would be highly appreciated.
Thanks in advance!
Answer by skovacs1 · Nov 23, 2010 at 04:15 PM
There are 2 simple explanations. I'm not sure which is the case here, but I would guess the first:
- One or both of your rigidbodies are sleeping. You would need to do something to wake them up either explicitly or implicitly. Perhaps you should consider having your cylinder be kinematic?
- Collision between these objects or layers has been disabled. Layer collisions can be checked/changed in the Project's physics settings or by calling certain function. Likewise, collision between individual objects can also be disabled through code. The IgnoreRaycast layer is automatically ignored by physics.
Hello and thanks for the reply
1.The kinematic flag has been checked for the cylinder in this case and still no results.The funny thing is it is colliding with my player at random intervals.Like it would collide on the first attempt and then maybe the third(random times) and then it would stop.Is this because of some technique used to check collision for the 3rd person controller? I have tried to replace the character with a cube and it works just fine. 2. I checked the physics setting and all layers have been checked so im sure that it hasnt been disabled in anyway.
Thanks in advance
You never mentioned that it collided sometimes - that changes the question a lot. The 3rd Person controller is just a script and has no bearing on collisions in and of itself. Do you have any other objects with colliders (maybe child objects of your character or something) that might be getting in the way? Also, for concave meshes, collisions and raycasts are somewhat unpredictable when using a mesh collider. Your best bet is to use a primitive (or at least convex) collider (like a capsule) or properly setup CharacterController Component (different from 3rd person character controller script).
Thanks a lot.I have made some progress now I removed the character controller and attached a standard box collider to my player and have attached a rigid body component to it.I wrote a simple animation script to contol the character animation.
This seems to work, as in the character is nowcolliding with the moving obstacle.But im not too impressed with the results.$$anonymous$$aybe i need to alter some values till i get it to work properly.