Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » General Dicussions » Request » Need an enter exit vehicle script please help

Need an enter exit vehicle script please help

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Need an enter exit vehicle script please help on Tue Sep 02, 2014 2:53 pm

FPS assault

Member [Lv. 3]
Member [Lv. 3]
I want to make it so i spawn a my fps player but if i walk up to my tank or jet ect and press E the player no longer moves and i can start driving the tank around and when im done i press E and it gets me out.Thank you

View user profile http://truefpscombat.wix.com/fpsassalt


This should have been posted in the Help(General) section of the forum.

--New Developer

View user profile
This system is not as simple as you may think.. its not one set of scripts and method to have a vehicle enter/ exit system, that functions in a way to enable vehicle mode and the default, so requesting someone to make you this whole system for free is a bit much.. Im sure you can find some good recources on how to do this, or better yet, you can find assets on the asset store.. But the main outline for this system is as follows:

Player enter Car trigger => Player learns of car's 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

View user profile http://www.youtube.com/user/misterninjaboy


Member [Lv. 3]
Member [Lv. 3]
ok you can do this very easily.

a few things you will reguire

add a trigger to the car depending on how you want it, generally near the drivers door.
add an empty GameObject to the car for where you will spawn when you leave the vehicle, generally at drivers door.
we also will use a boolean because we are making a toggle script

i use the examplle : bool inVehicle;

add a script to the car as the car will determine weather you are near it or not

add this function


OnTriggerStay(Collider col)
if(col.tag == "Player" && Input.GetbuttonDown(KeyCode.E) && inVehicle == false)
//we trigger the inVehicle bool to true
inVehicle = true;

//or may need to use
col.enabled = false;
//find which one of the 2 above will work.

//now we need to enable this vehicles controller scripts.

gameObject.getcomponenet<MyControlelerScript>().enabled = true;

//if the above does not work use SetActive(true), if neither work

//now we need to do the same thing as above in reverse to get out of the vehicle, but we dont care about the trigger anymore because our new player is the vehicle.


  if(Input.getKeyDown(KeyCode.E) && inVehicle == true)


//first while the player is disabled, we need to move his pos to our vehicles Spawn Point, we will enable the player last.

/*if this does not work it might be because the player is disabled, might have to do the moving whe nwe enable the player just do it one line after we enable the player so they dont see the glitch move. but i dont think this will be a problem. */

GameObject.Find("Player").transform.position = SpawnPoint.position;

//set the inVehicle bool to false
inVehicle = false;

 //GetComponenet on the vehicle controls and camera also if you need to and disable them.

//now we need to enable this vehicles controller scripts.

gameObject.getcomponenet<MyControlelerScript>().enabled = false;

//if the above does not work use SetActive(true)

//now we can enable the player to control.

//or if that does not work

GameObject.Find("Player").enabled = true;



this is a guide to how to do it, most of the code should work fine but might need some tweaking, this is not very difficult to do.

only things you really need to do is add a player spawn poinjt to each vehicle, where you want them to spawn when they leave the vehicle, and secondly you need a way to interact with the vehicle, generally by a trigger on each vehicle. and all you need now is to talk to both player and vehicle to enable/Disable correct components and you are done. oh and also when you leave the vehicle just need to pop the player to your vehicles spawn point pos which you can do by referencing a public Transform or GameObject on each vehicle.

hope this explains it all out for you =)

View user profile http://jakeaquilina.weebly.com/

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum