Search Unity

rear view window

Discussion in 'Scripting' started by ognjenm, May 11, 2011.

  1. ognjenm

    ognjenm

    Joined:
    May 3, 2011
    Posts:
    97
    car rear view window script , how to make it?

    and car light :))
     
    Last edited: May 11, 2011
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Car lights are fairly simple, I would suggest using the Standard Assets Projector (use the light one) and just outfit it to the front of the car and set it's distance. Make sure it is set to not show on the layer that the vehicle is on and you are set.

    As far as the rearview. I kind of wanted to know it myself and I knew that somewhere on this site there was a MiniMap tutorial. This is exactly the same as a rear view mirror, you just position the camera to make it work.

    I found the tutorial here:

    http://www.moddb.com/games/caredu/tutorials/how-to-make-a-minimap
     
  3. alverndbl

    alverndbl

    Joined:
    Jul 11, 2010
    Posts:
    25
    I think the official Unity Car tutorial has a rear view for the Player Car. You should check it out how they do it.
     
  4. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Just for clarification and if anyone finds this using the search for Minimap... this is adapted code for that tutorial:

    Code (csharp):
    1.  
    2. var target : Transform;
    3. var damping = 6.0;
    4. var smooth = true;
    5. var height = 90.0;
    6.  
    7. function LateUpdate () {
    8.   if (target) {
    9.     if (smooth)
    10.     {
    11.       // Look at and dampen the rotation
    12.       //var rotation = Quaternion.LookRotation(target.position - transform.position);
    13.       var originalRotation=transform.rotation;
    14.       transform.LookAt(target, target.TransformDirection(Vector3.forward));
    15.       transform.rotation = Quaternion.Slerp(originalRotation, transform.rotation, Time.deltaTime * damping);
    16.     }
    17.     else
    18.     {
    19.       // Just lookat
    20.         transform.LookAt(target, target.TransformDirection(Vector3.forward));
    21.     }
    22.     transform.position = target.position + Vector3(0,height,0);
    23.   }
    24. }
    25.  
    26. function Start () {
    27.   // Make the rigid body not change rotation
    28.     if (rigidbody)
    29.     rigidbody.freezeRotation = true;
    30. }
    31.  
    I found the original code to be rather jerky.
     
  5. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Question would be is how to reverse the X of the camera, so that it actually looks like it's mirrored?
     
  6. ognjenm

    ognjenm

    Joined:
    May 3, 2011
    Posts:
    97
    Last edited: May 11, 2011
  7. ognjenm

    ognjenm

    Joined:
    May 3, 2011
    Posts:
    97
    new problem how to rotate it look $1111111.jpg
     
  8. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Thats actually pretty easy, the same script, but you don't update the camera position each frame. and link it to the vehicle's root transform.

    Recant.....

    Dont put the mini map script on it.. ;)
     
  9. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
  10. EmeraldThunder

    EmeraldThunder

    Joined:
    Jan 10, 2016
    Posts:
    50
    Amazing....can you add script for Car so it moves to where you click by mouse??