Search Unity

How would you go about scripting a third person view

Discussion in 'Editor & General Support' started by melligeorgiou, Aug 11, 2005.

  1. melligeorgiou

    melligeorgiou

    Joined:
    Aug 10, 2005
    Posts:
    8
    I've popped a little space ship into my scene, and now I want to make this spaceship be the main character as it were.

    How would I go around scripting this? Any examples?
     
  2. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    The is a Prefab unit in the Standard Assest folder you can use the whole thing or look at the two assocated scripts FSWalker and LookAt and expand from there.

    Richard.
     
  3. Krispy

    Krispy

    Joined:
    Jun 6, 2005
    Posts:
    69
    Yay! I get to be useful!
    If you just want the camera to follow the player at a fixed location, just parent the camera to the player.
    Use the GUI or put

    Code (csharp):
    1.  
    2. public Transform player;
    3.  
    4. void Awake(){
    5. transform.parent = player;
    6. }
    7.  

    If you want the camera to be able to rotate independently (because parenting copies position, rotation and scale) things get a bit more complicated.

    create an empty GameObject and move to so that it's in the same place as the player. Put this code on it:
    Code (csharp):
    1.  
    2. public Transform player;
    3.  
    4. void FixedUpdate(){
    5. transform.position = player.position;
    6. }
    7.  
    Then parent the camera to the GameObject.

    Hope that helps.
     
  4. melligeorgiou

    melligeorgiou

    Joined:
    Aug 10, 2005
    Posts:
    8
    Thanks for the feedback guys! And yes you've been very useful! ;)

    I'm gona fiddle around with it some more and let you guys know how I get on!

    So far I must say that this community is a whole lot better than others, especially garagegames where the users can be very rude and synical.

    You can tell we're Mac users, we give respect to people who try, and spread the word almost like a religion! ;) LOL

    Anywayz, enough preaching from me!