- Home /
Entering And Exiting Car
I know this question is asked a lot but I can't figure it out. I have a car with this script:
var FrontLeftWheel : WheelCollider;
var FrontRightWheel : WheelCollider;
var GearRatio : float[];
var CurrentGear : int = 0;
var EngineTorque : float = 230.0;
var MaxEngineRPM : float = 3000.0;
var MinEngineRPM : float = 1000.0;
private var EngineRPM : float = 0.0;
function Start () {
rigidbody.centerOfMass += Vector3(0, -.75, .5);
}
function Update () {
EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm)/2 * GearRatio[CurrentGear];
ShiftGears();
audio.pitch = Mathf.Abs(EngineRPM / MaxEngineRPM) + 1.0 ;
if ( audio.pitch > 2.0 ) {
audio.pitch = 2.0;
}
FrontLeftWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis("Vertical");
FrontRightWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis("Vertical");
FrontLeftWheel.steerAngle = 10 * Input.GetAxis("Horizontal");
FrontRightWheel.steerAngle = 10 * Input.GetAxis("Horizontal");
}
function ShiftGears() {
if ( EngineRPM >= MaxEngineRPM ) {
var AppropriateGear : int = CurrentGear;
for ( var i = 0; i < GearRatio.length; i ++ ) {
if ( FrontLeftWheel.rpm * GearRatio[i] < MaxEngineRPM ) {
AppropriateGear = i;
break;
}
}
CurrentGear = AppropriateGear;
}
if ( EngineRPM <= MinEngineRPM ) {
AppropriateGear = CurrentGear;
for ( var j = GearRatio.length-1; j >= 0; j -- ) {
if ( FrontLeftWheel.rpm * GearRatio[j] > MinEngineRPM ) {
AppropriateGear = j;
break;
}
}
CurrentGear = AppropriateGear;
}
}
And It works fine but I want to be able to (When I'm close to my car, press "return" and then I get in my car and I can Drive that; my player disappears. Can Someone please Walk me through on how to do this?
Thanks so much in advance
-Bruno
Answer by nixtwiz · Jul 05, 2012 at 05:24 AM
The script/tutorial is in one of the answers. To walk through the script quickly,
1.the player is touching the enter collider and presses key 2. the player's location is changed to the car's and it is parented to the car 3. the player is made invisible 4. the player is disabled 5. the car is enabled 6. Player camera is disabled 7. car camera is enabled
This video helps you set it up, you might need to watch the other two as well. Entering and Exiting Vehicles
nothing happens I did everything in the tutorial- nothing
Did you follow all the videos? most importantly the correction video, he messed up in the first one.
I know the script works, I've used it myself numerous times. Double check with the videos that its set up correctly :)
Are u sure that the video works? Because i am a very young developer of 10 and a half years so i need a free working script for my game. plz help u need email?here it is: shahsohaib09@gmail.com help plz...
Answer by waqas007 · 3 days ago
Visit this link for car enter exit system: https://incern.blogspot.com/2022/06/car-enter-exit-system-c-unity-demo.html
Watch this Video for car enter exit system: https://www.youtube.com/watch?v=gLu3g_iNQDE&ab_channel=WaqasKhalid
Your answer
Follow this Question
Related Questions
JS Enter Exit with NetworkPlayer 1 Answer
Enter/exit buildings spawn 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Enter/Exit vehicle 0 Answers
could someone help with entering/exiting a vehicle? 0 Answers