- Home /
Random Collision on PlayerCharacter?
I have created a series of meshes when placed together create a house, and I created a few meshes that surround that walls and windows, etc to use as a collision mesh. I did not generate collision on the meshes on import because I was going to use my own. I placed the mesh, and added several empty game objects that I put MeshColliders on. I select my collision meshes that I want to use for the collision, and everything works fine. But as my PlayerCharacter is moving around, I can tell it is getting pushed aside on random collision that is not there. It's as if there are thin strings from the top to bottom and as the PlayerCharacter hits the strings, they slide around them after a small bump. It's noticeable but there is nothing there on my collision. I'm not able to post a video showing it as it hard to detect, but I can see it in multiple locations across my mesh. I know which collision mesh is causing the problem, as the issue is gone when I deactivate the object. The strange thing is that the mesh that is causing the problems is isolated to the "bottom floor" of the house, in which the PlayerCharacter isn't even intersecting with the collider. But as I said earlier, its as if random edges of the mesh are shooting upwards into the upper floor of the house. Is there any ideas or suggestions on how to fix this, or why it's even happening?
Add some Debug.Log() calls to when your player collides with something. If you know they're touching the floor tell it to ignore floor calls when you go to call Debug. You gotta find out what you're running into first. There's never anything strange going on and it will make total sense when you figure it out. try turning off all the other colliders if you know which one it is, and see what's going on. Or maybe try loading it up in blender and seeing if the mesh has an error or funky face somewhere.
Well, I know its the bottom highlighted mesh in the above image because I disabled them individually to find the one as you suggested beforehand. But upon doing collision tests, I can not seem to get a script to work on that. I'm assu$$anonymous$$g this is correct? using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TestCollisionBug : $$anonymous$$onoBehaviour {
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.collider.name != "_collision_g_floor")
Debug.Log( hit.collider.name );
}
The collision marked in the Debug call is the floor that the character walks on, so I don't display those messages. But just in case that the problem mesh is the floor, I disabled it, and replaced it with a Plane. I can still clearly tell that I'm hitting something, but the script is not saying I'm hitting anything. I can touch a wall, or walk through a door, and I get a message, but when I hit the "invisible line" that bumps my character, no message at all. So according to Unity, I'm not colliding with anything. What is causing the unwanted "collision" then?
This is not the only mesh causing problems. Just that location in the image is the result of the collision mesh. Other locations in the scene have the same issues because of the other collisions, but nothing is reported to the console, so I can't tell whats going on.
well... not sure. You want me to look at your scene? You can private message me a link.
If you're not getting a collider debug it's probably not an actual collision. Your using a character controller right? Is the height limit... slope limit really low? Is your player using a simple capsule collider?
Here is a video that better demonstrates what is going on. Note that the character is only moving forward. No other buttons are being pushed.
Answer by Skeletim · Feb 05, 2017 at 09:21 PM
It seems like the bottom two meshes that were used as collision had issues computing collision with faces that had the normals facing up. When I deleted those faces, the collision disappeared. And as you can see from the images I posted before, the character controller was not even touching the two bottom meshes. But it was indeed those two meshes. I don't know why the faces had issues. Thanks for the help Malkere
Answer by malkere · Feb 05, 2017 at 02:07 AM
well.. I fixed it, I'm not totally clear as to why I had to do what I did.... Basically it is your ceiling.
Your ceiling was overlapping in several places with the wall and the second floor. I don't know why your character collider wasn't showing the collisions, but if you increase the size, I made him radius 0.5, height 2, then it was reporting collisions with the ceiling and the wall as well as the floor (make sure you use collapse in the logs). After I removed the overlapping faces, which can't be seen or touched anyway, so shouldn't be there, it works fine.
Somehow the physics engine was having trouble calculating them as exactly the same and there were some arguing collider faces where they were overlapping is all I can guess.
What about the back hall? Isn't that also colliding with the bottom collision mesh? Did you see the character collide while walking down the hall?
I played around with those meshes, and I can remove that mesh altogether and still get the issue. The problem persists until I remove or disable the bottom two meshes that are not even touching the player's character controller. The ceiling was not the problem unfortunately. As having the meshes just the way you have it now, still I get bumped. Its those two meshes I mentioned that when I remove from the scene, the problem goes away. But you can see its not causing any collision from the image. And yes, I did make the corrections that you suggested with no luck. Does anyone understand whats going on?
Could this issue be a bug in the engine with how it deals with collision meshes?