Search Unity

Camera Collision And Its Woes

Discussion in 'Scripting' started by Hypocrita_20XX, Dec 25, 2014.

  1. Hypocrita_20XX

    Hypocrita_20XX

    Joined:
    Feb 8, 2014
    Posts:
    27
    Hello and good evening everyone!


    I'm essentially looking for some general ideas/advice as to how I might achieve a certain effect with the camera.

    At this moment, my camera setup is a little complicated, but I'll go over it regardless.
    I have what you might call a global center that is at the player's position at all times, but rotates independently.
    I also have, attached to that, a local center, offset to the right of the player.
    Attached to that, finally, is the camera, and a target look at that the camera always looks at, each offset along the Z axis from the local center.
    The global center handles rotation about the Y axis, and the local center, rotation about the X axis.
    Everything is set up in this way so that I get the desired camera effect that the project requires, primarily one that makes third person aiming more user-friendly.

    Now, to the matter at hand: camera collision.
    I could go about this in many, many ways, but so far, none have really meshed with the system I have currently set up simply because it's not as simple as "camera here, player there, look at and orbit around them."
    What I've currently thought of doing is predicting the camera position a frame ahead, and if it collides with something (using raycasts for directional detection,) cease rotation, move the camera and local center forward by a reasonably small amount, check for collision at this new point, rinse and repeat until no collisions are detected or the camera is close enough to the player where it won't matter.
    As to why this doesn't work is mainly based on the fact that the camera typically is always at a point where movement is no longer relevant, that it won't "save" the system from doing undesired things.

    So I figured: why not make the prediction go out further? Why not make it go out, say, five or ten frames ahead? And if it sees an issue, start moving the camera right away.
    This seems to pose other problems, like if the player switches rotation directions before five or ten frames pass, then the camera could get stuck mid-movement.
    Then, of course, there is the fact that I have very little idea as to how to implement such a prediction method!

    I don't know, every solution appears to have its own unique set of problems, so I would appreciate some outside ideas and thoughts, like what you have or would personally do in this situation with this kind of camera system.

    Thanks for your time, and take care!
    -Hypocrita