Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Spring Camera - Camera can't go through objects

Discussion in 'Scripting' started by Teriki Tora, Dec 10, 2010.

  1. Teriki Tora

    Teriki Tora

    Joined:
    May 21, 2010
    Posts:
    132
    Yup, me again. This time I'm looking at getting my camera to do something extra, but not just one camera, all of my cameras. What I'm looking for is a script (or scriptlet that I can add to previously existing code) that tells my camera to zoom in or move away when my character backs into a wall. I know what the first answer is! "Use the Lerpz tutorial SpringFollowCamera"

    I did it, I used it, it doesn't work. It just does nothing and my camera goes through my objects anyways. Also note that the line-of-sight mask also doesn't work (same tutorial), as anything within the line of sight doesn't go transparent. I've also checked the script database at the Unify community wikia, but it didn't have anything that I was looking for either (just a simple camera switcher, which I plan to use for full-view-rotation without my character rotating).

    I also did a search (as I always do before posting something) on the same thing, but the closest I got with the WoW Camera, but that doesn't exactly give the spring effect I'm looking for, but more-so a snap-back effect when you let go of the mouse and you start moving forward (something I will use with my second camera, I have that sorted out). Right now I have a camera that likes to go through my objects, completely obscuring my character. And because I plan to have indoors... That means that my camera will begin to view the outside, and if there are any enemies my player won't be able to see them.

    So to sum it up, I'm looking for a script that makes the camera "squash" towards the character as it backs into walls, and as my character runs away from the walls, the camera goes back the the user-declared distance (whatever it was at before the "squashing"). A big PLUS if it is a separate script that I can add to any camera I want (and omit it from any camera I want).
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,935
    hi,

    Not sure if you mean something like this.

    Info:
    - Shoots ray from back of the head
    - If we hit something, move camera to the hit.point (this helps to keep camera inside walls)
    - If we didnt hit anything, keep camera at set distance

    Webplayer:
    http://sinun.net/unity/camray1/
    controls:
    wasd = move around (using std First Person Controller)
    mouse = look around player

    Try backing against the wall,
    or go near wall and turn around cam.

    Download:
     

    Attached Files: