Script for entering vehicles

I need a script for when my player approaches a vehicle he can “enter” it and begin driving (the vehicle is a separate controller)Does anyone have a script I can please use for this?

You should try and make it yourself and ask for help instead of just asking for the script. You’re most likely not gonna find someone who will just give you the code when it will most likely be a long one.

It shouldn’t be that long, essentially all I need is a script for changing the controller in level

Then it should be easy enough to write yourself.

Like FreelandCJV suggested, just dive in, and then post back here if you run into any problems. (If you post some code along with a description of any problems you’re having with it, people will likely be happy to help.)

I think asking for a direction to go in, instead of script, is also pretty well accepted (at least I don’t mind it). Here’s an approach I would suggest.

There would be a boolean variable in both the player and the vehicle. These toggle when they have control over input. When a player has control, their var is set to true. When they enter the vehicle, it’s set to false. The inverse of this would occur in the vehicle. When the player exits the vehicle, their variable is set to true, while the car’s is set to false.

If this is confusing, I will attempt a “pseudo-code” approach.

In the player’s controller:

if(playerCharacterHasControl){

    //other input here

    if( button to enter car is pressed while near a car) {
        playerCharacterHasControl = false;
        signal the car's controller that it has control by setting it's variable to true
    }
}

In the car’s controller:

if(carHasControl) {
    
    //other input here

    if(exit car button has been pressed) {
        carHasControl = false;
        signal to the player's controller that it has control, setting it's variable to true
    }
}

Again this is more of a conceptual approach to what you want. See if this gets some coding sparks going off. Sometimes all you need is a direction. :slight_smile:

Buckethead,

you can find ALOT ALOT ALOT of scripting help at Unity - Scripting API:

you might just find somthing to help you out!

Buckethead is awesome. For those that dont know,
click this