Hi there,
I am working on a FPS type of game, and I want the player character to be able to get in/out of drivable vehicles. Can anyone help me perhaps?
Well looking at that video, i think all that happens is a trigger on the doors of the car, activating that trigger simply switches of the fps player and camera and enables car controls and car camera.
Both are controllable. When I run my project, the tank and character react on the same inputs.
I have the following javascript, but somehow it does not work.
// This script is for getting in and out of vehicles//
var player : Transform ; // drag the player here
var enterRange: float = 8.0; // distance to enter the tank
var exitPos = Vector3(0, 1.5, 0); // exit position relative to the tank
private var cam : Camera; // tank camera
private var inTank = false; // tells when the character is inside the tank
function Start(){
cam = GetComponentInChildren(Camera);
cam.enabled = false; // make sure the tank camera is off
}
function EnterTank(){ // enters the tank:
player.gameObject.SetActiveRecursively(false); // deactivate the original player...
cam.enabled = true; // and activate the tank camera...
inTank = true; // and controls
}
function ExitTank(){
// move the player to its exiting position:
player.position = transform.TransformPoint(exitPos);
player.gameObject.SetActiveRecursively(true); // reactivate the original player...
cam.enabled = false; // and deactivate the tank camera...
inTank = false; // and the tank controls
}
function Update(){
if (inTank == false); // if outside the tank...
// and E pressed while player inside the enter range:
if (Input.GetKeyDown("e") Vector3.Distance(player.position, transform.position));
}