Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Get into cars help

Discussion in 'Scripting' started by peiroxswe, Nov 17, 2007.

  1. peiroxswe

    peiroxswe

    Joined:
    Nov 17, 2007
    Posts:
    11
    Hello

    Im new to unity and im creating a gta inspired game.
    I need help with get into cars.
    Any suggestions??

    //jacob
     
  2. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Hiya, theres a few ways to do this. Bear in mind if you want to include the door opening, drag driver out animation, it will take a bit of figuring out. If I was tackling this I think I'd find the trickiest part moving the character from runaround mode to the correct position to play the door open anim. Jeremyace had some suggestions for that somewhere.

    This is how I would've done something like this a year ago. I'd probably do it slightly different now, only because I understand scripting a lot more.

    http://forum.unity3d.com/viewtopic.php?t=2278&postdays=0&postorder=asc&start=30

    Theres a package you can look at there. Its one way to do what you want, without the animation. Eric5h5 posted a thread called storm city-camera paths and theres a good script there for handling switching control systems. With credit to Eric, I'll repost it here with the varibles included, just to make it a bit easier to follow.
    Code (csharp):
    1. var player: GameObject;
    2. var playerCam: GameObject;
    3. var vehicle: GameObject;
    4. var vehicleActive = false;
    5.  
    6. function Update () {
    7.    if (Input.GetButtonDown("Bailout")) {
    8.       if (vehicleActive) {
    9.          vehicleActive = false;
    10.          vehicle.GetComponent(Camera).enabled = false;
    11.          player.active = true;
    12.          playerCam.active = true;
    13.  
    14.          player.transform.position = vehicle.transform.position;
    15.          player.GetComponent(MouseLook).rotationX = vehicle.transform.eulerAngles.y;
    16.       }
    17.       else {
    18.          vehicleActive = true;
    19.          vehicle.GetComponent(Camera).enabled = true;
    20.          player.active = false;
    21.          playerCam.active = false;
    22.       }
    23.    }
    24. }
    This is a good script to work from. If facing this situation again, I'd start here. Good luck, keep us in the loop with your progress.

    AC
     
  3. peiroxswe

    peiroxswe

    Joined:
    Nov 17, 2007
    Posts:
    11
    Thank you Targas

    //jacob