Vehicle Enter/Exit System for First/3rd Person :)

Hello People,

MY SCRIPT WILL BE AVAILABLE ON THE ASSET STORE FOR $15 VERY SOON!!

A GTA STYLE GAME WOULDNT B POSSIBLE WITHOUT IT!!!

WHAT IT CAN DO:

You can Simply run up to your car, press a key ("e" in my case) and enter your car. at this point your character is invisble and you can drive your car around while your invisible character gets steady moved with it. after pressing another key - (in my case "r") your character gets visible again and stands right besides your car. and you are now able to controll your character again while your car still stands where u left it. :)

i made a video tutorial ill upload it tommorrow :)

Hello, i neeed help with the script. What tags i must use. On FPS the PLayer tag and on the carobject car tag? And in your script the line GameObject.Find("car").GetComponent("DrivingScript") the string DrivingScript rename? It doesnt work. Is there a videotutorial? Thanks for help

Ohh, and don't post the solution into the question! It's a total mess already. I don't have the time to disassemble this mess and reorder it. Please let the question be a question and post an answer if you have a solution. You can edit your posts at any time.

then why dont u just leave it how itt is man? thats why most people cant get what they are looking for that easy.

no way 99 dollars? thats bs, i saw the script its one of the simplist scripts ive seen and its not worth money at all, im sick of these greedy assholes charging way to much money for shit people either dont know what does or stuff they didnt ask for, it makes it near impossible for any newbie trying to do even the simplist things in unity, i even had problems finding info about how to code. its literally easier to design your own assets completely because all the shit on the asset store is overpriced stuff your lean to do yourself anyway

8 Answers

8

Here its me again with general answer. I won't code the whole thing, but try something along these lines and come back with your problems. If you don't need anything fancy, here's how you could order things:

  • Player enter Car trigger => Player learn of car existence
  • Player hit a key and a car is known => function enterCar
    • Play animation?
    • Destroy Player / Disable Renderer / Hide under terrain
    • Give control to car > Enable Script / Set a boolean variable
    • Move around
  • Player hit a key = > function exitCar
    • Take control off car
    • Play animation?
    • Instantiate Player back at the left of the car
    • Give control back to player

Can't believe I wrote all this, scripting would've been just as long but then I'd have done all the work ;)

hey thx for this i got it now working halfways :) animations are not that important for now ill add them later as soon as i have created some XD ... So my character is disabled and invisible on key hit (made use of your last answer to achieve this ) and parented to the trigger thats also parented to the car :) but i cant figure out how to reverse the whole thing ... i mean unparent the character. May i show you my code im using now?

You can if there's something to look at :) . Otherwise, try someObject.transform.parent = null;

From this point, specific questions should be asked as such as this site is not for general programmation question or ordering scripts. Search Unify/Unity3DStudent/Unity Scripting Reference as much as you can, that's how we all learned, not so long ago.

Hello People,
ALREADY FOUND A SOLUTION FOR MY PROBLEMS…WROTE MY OWN SCRIPT … just ask me if you dont know how to set it up… its very easy…

HERES THE TUTORIAL I MADE FOR IT IN A WORD DOCUMENT … make sure to CREDIT ME (GOLDYUNGE) when using and do not share or sell the script on your own.

http://www.mediafire.com/?2amo3r25nyzzgd7

DUPLICATE AND CALL THE FOLLOWING SCRIPT “VehicleDoorLeft” & “VehicleDoorLeft”

WHAT IT CAN DO

You can Simply run up to your car, press a key (“e” in my case) and enter your car.
at this point your character is invisble and you can drive your car around while your invisible character gets steady moved with it.
after pressing another key - (in my case “r”) your character gets visible again and stands right besides your car. and you are now able to controll your character again while your car still stands where u left it. :slight_smile:

KNOWN ISSUES:

YOU CAN ENTER THE VEHICLE FROM EVERYWHERE YOU ARE?

SOLUTION: **DISABLE** the "*isPlayerVisible*" box by Default before you start the game.

Your problem will be solved.

Do NOT set another gameObject with a Collider Attached to it as a child of your Player Character.
Whether you deactivate the collider or set it as “is Trigger”.
Otherwise your Car will behave VERY VERY STRANGE and you dont want this to be happen :wink:

var car : Transform;
var player : Transform;
var exitPoint : Transform;
var doorTriggerLeft : Transform;
var PlayerCamera : Camera;
var CarCamera : Camera;
var isPlayerVisible : boolean;


function Update(){
    if (Input.GetButtonUp("Action")&& isPlayerVisible){
        // make player invisible and still standing
        player.gameObject.SetActiveRecursively(false);
        player.gameObject.active = false;
        // parent player to Exit Point
        player.parent = exitPoint.transform;
        player.transform.localPosition = Vector3(-1.5,0,0);
        // parent PlayerParent to car
        exitPoint.parent = car.transform;
        exitPoint.transform.localPosition = Vector3(-0.5,0,0);
        // Enable Car as controllabe object
        GameObject.Find("car").GetComponent("DrivingScript").enabled=true;
        PlayerCamera.enabled = false;
        CarCamera.enabled = true;
        }
        else
        {
    if (Input.GetKeyUp("r")){
        // make character visible again
        player.gameObject.SetActiveRecursively(true);
        player.gameObject.active = true;
        // unparent player from everything
        player.transform.parent = null;
        // parent Exit Point to door Trigger
        exitPoint.parent = doorTriggerLeft.transform;
        // disable car as controllable
        GameObject.Find("car").GetComponent("DrivingScript").enabled=false;
        PlayerCamera.enabled = true;
        CarCamera.enabled = false;

        }   
    }
}

function OnTriggerEnter(Player : Collider) {
    isPlayerVisible = true;
    }

function OnTriggerExit(Player : Collider) {
    isPlayerVisible  = false;
    }

Dude! This works awsome thanks so much for the post! You are the man!

MINE DOESNT WORK I TOOK A YOUTUBE VIDEO TO SHOW YOU!! http://www.youtube.com/watch?v=QHH3ntkF-H0&feature=youtu.be help please

what version are you using?

it works with all versions of unity

i wrote this in java script :)

I created a video tutorial for the script’s implementation. I didn’t tag the ‘car’ to vehicle, tag it according to ‘Yung Hustla’. This script works really good, good work bro!

First Video:

Second Video:

FIX*** You have to set is Player Visible" OFF in order to only enter the car if you hit the collider. That ist what the last two lines on the bottom on the script stand for.

mine don't even enter the car at all.

check out the very easy to ndertand tutorial ive wrote for this in addition you can check out the youtube tuturial that "strongme" made for us :)

Hey my script says Assets/_Scripts/EnterExit.js(24,71): BCE0019: ‘enabled’ is not a member of ‘UnityEngine.Component’.
please help since I am only a modeler :slight_smile:

I have the same error as iflirt456. Please help!

@ifirt456 open scipt and changes in the script to enable and then go in unity and edit> projectsetting> input then change the number in size 19 to 21 and then change the name of the last two with "e" and "r", put "and" in the alt button negative and also another sun that you put "r" in the negative alt button ... I hope you will both help ;)

make enabled active

I get the same thing : Assets/_Scripts/EnterExit.js(24,71): BCE0019: 'enabled' is not a member of 'UnityEngine.Component' Then if I use active instead I get : Assets/CarEnterScript.js(39,67): BCW0012: WARNING: 'UnityEngine.Component.active' is obsolete. the active property is deprecated on components. Please use gameObject.active instead. If you meant to enable / disable a single component use enabled instead. its a vicious circle lol then gameObject.active is Obsolete so its gameObject.SetActive then your back at is not a member of 'UnityEngine.Component' going crazy !

when i press e nothing happens

youll have to create a new input button called "Action" and set the positive key as "e"

I am very confused I think I have tried those scripts before and they didn’t work

it definately works for ervybody. check out my tutorial ive attached to the script its very easy to understand just follow my instructions. i will work for u you just hav to set it up right

When i exit the car, while its driving it just drive away into eternity.
is there a way to make it break or roll out when you leaving it?

Der_Kevin, add Drag to the car so that it slows down after the acceleration key has been let go.