Search Unity

FPS1.11 ETeeski Tutorials

Discussion in 'Scripting' started by jbecana, Mar 29, 2012.

  1. jbecana

    jbecana

    Joined:
    Feb 14, 2012
    Posts:
    22
    Looking at the part of the code to zoom in/out, I've seen in other parts of these tutorials that we are using both smoothDamp and Lerp interpolations at the same time.
    I mean, this is the actual code:

    if ( currentAimRatio == 1) // We are not aiming at enemy
    {
    zoomRatio = Mathf.SmoothDamp ( zoomRatio, 1, zoomRatioV, ZoomSpeedRatio);
    }
    else
    {
    zoomRatio = Mathf.SmoothDamp ( zoomRatio, 0, zoomRatioV, ZoomSpeedRatio);
    }
    camera.fieldOfView = Mathf.Lerp ( aimingCameraZoom, defaultCameraZoom, zoomRatio );

    I'd tried this one with very similar result apparently :

    if ( currentAimRatio == 1) // We are not aiming at enemy
    {
    camera.fieldOfView = Mathf.SmoothDamp ( camera.fieldOfView, defaultCameraZoom, zoomRatioV, ZoomSpeedRatio);
    }
    else
    {
    camera.fieldOfView = Mathf.SmoothDamp ( camera.fieldOfView, aimingCameraZoom, zoomRatioV, ZoomSpeedRatio);
    }

    Thanks in advance.
     
  2. eteeski

    eteeski

    Joined:
    Feb 2, 2010
    Posts:
    476
    I suppose i probably could've done it like that. I think it's a bit of habit for me. I've had problems in the past with transforms, and what i found was that things seemed to work more efficiently when outside variables are only manipulated once. So I was trying to figure out what camera.fieldOfView had to be and then change it to that only once per frame, as opposed to manipulating it directly. With unity3.5 though, it might not be a problem anymore. Unity3.5 seems to have fixed a lot of issues like this and generally makes everything run better and the way you'd expect it to.
     
  3. newfinalflashers

    newfinalflashers

    Joined:
    Mar 1, 2014
    Posts:
    27
    Hi eteeski I am following your fps tutorials as well and I would like to know if there is anyway to optimize the ai scripts to work for map switching and multiplayer thank you for your awesome tutorials.