Quantcast
Viewing all articles
Browse latest Browse all 18

Camera Stuck on Wall Corners

Hello all, So here's the deal. I have a camera parented to a gameobject that rotates based on the mouse or right control stick on the controller. When it rotates, the offset camera "orbits" around to create an kind of fake mouse orbit for the camera. I also put a sphere collider and a rigidbody on it so it wouldn't go through walls. This was pushing the camera to odd angles, so I wrote a script that detects collisions with the environment, or at least objects tagged as "environment". It will be pushed around for as long as the collision in happening, but after the collision exits it will slerp back to its start position offset from its parent. This works pretty well. However, I'm finding that as the player walks around sharp corners, the camera gets stuck on the corners. It drags along the edge until A) the player manually rotates the camera around the corner when it will promptly tween back to the correct position or B) it drags to the edge of the corner after some time, is able to exit collision, then tweens back to the correct position. This can take a while as it drags along the wall very slowly. I tried decreasing the drag and angular drag settings on the camera's rigidbody property (they are usually set to infinity), but it just allows the camera to bounce around in an unwanted manner if it collides too hard, it has no bearing on the friction. Speaking of, I have attached a physics material to the collider on the camera with zeroed friction settings up and down, but that doesn't seem to make a difference having it on the collider or not. My current solution is to check the distance between the camera and its parent and if it's past a certain distance, to automatically tween it back to its starting position. However, this causes the camera to fly through walls ignoring collisions altogether. This isn't ideal, as I don't want the camera to see through walls. So I think the correct thing to do would be to implement some sort of pathfinding intelligence for the camera if the distance check fails. However, I'm not the guy on our team working on AI, in fact I don't even know him and he's working remotely, so I can't ask his advice. That is to say, I have no experience with pathfinding. I could learn some pathfinding basics to get this figured out, but I'd rather not take the time out of my work cycle right now if this isn't the way to go. So my question is: Will I find the answer to my issue in pathfinding, or is there a better way to deal with his issue? Thanks! -Long-winded Panopolos

Viewing all articles
Browse latest Browse all 18

Trending Articles