Jump to content
juleshuxley

Stop vehicle braking when driver changes seats.

Recommended Posts

When I'm the only person in a vehicle and I change seats, the vehicle screaches to a halt as if the brakes have suddenly been slammed on. Is there a way to supress this in a script? If you were to scramble into a gun turret from the driver's seat the vehicle would keep rolling under in its own inertia. How do I stop the brakes being slammed on? It happens if I teleport out of the vehicle as well. If arma detects no driver, the brakes come on it seems.

  • Like 2

Share this post


Link to post
Share on other sites

It's almost like Arma devs didn't want you to be able to drive a car full of C4 at a bunch of enemies and bail out at the last second 🤔

  • Haha 3

Share this post


Link to post
Share on other sites

Most probably you could use an event handler to call when you switch the seat. From there you could possibly call a script that handles the deceleration of the vehicle. The event handler would look something like

// Place this inside the init of the vehicle for example
// Add the event handler to the vehicle
this addEventHandler["SeatSwitched", {
	// Get the parameters
	params["_veh", "_unit1", "_unit2"];

	// Find out which unit is the player
	// (this may be redundant if you know that you are the
	// only unit in the vehicle, or the first unit is
	// always the one that initiates the move. This has
	// to be tested though).
	private plr = 0; // Initialise the variable
	
	// Do the test
	if(_unit1 isEqualTo player) then {
		plr = _unit1;
	} else {
		plr = _unit2;
	};

	// Make sure you moved out of the driver seat
	if((driver _veh) isEqualTo _plr) then {
		// Call the script to handle the vehicle's movement
		private _nil = [_veh, _plr, 0.99] execVM "You_handleVehMove.sqf";
	};
}];

Please keep in mind that if you intend to use the script only in the case where you are the only person in the vehicle and you are driving, you could simplify it into something like

// Place this inside the init of the vehicle for example
// Add the event handler to the vehicle
this addEventHandler["SeatSwitched", {
	// Get the parameters
	params["_veh"];
      
	// Call the script to handle the vehicle's movement
    private _nil = [_veh, _plr, 0.99] execVM "You_handleVehMove.sqf";
}];

And the script that handles the movement could be something like

/*
 * You_handleVehMove.sqf
 */

// Get the parameter
params["_veh", // The vehicle
	   "_plr", // The player
	   "_dec"]; // The deceleration factor

// Get the speed of the vehicle
private _speed = speed _veh;

// Decelerate until the veh has reached a small speed value (in this example 1 km/h)
while{_speed >= 1 || {(driver _veh) isEqualTo _plr} do {
	// Get some values
	private _vel = velocity _veh; // Velocity of vehicle (vector quantity)
	private _dir = direction _veh; // Direction of the vehicle (vector quantity)

	// Change speed according to deceleration factor
	_speed = _speed * _dec;

	// Set the new velocity of the vehicle
	_veh setVelocity [
		(_vel select 0) + (sin _dir * _speed), // Set speed on X-axis
		(_vel select 1) + (cos _dir * _speed), // Set speed on Y-axis
		(_vel select 2)]; // Set speed on Z-axis
};

Please note that the deceleration factor is an arbitrary factor and if you want to calculate it in km/(h^2) you would have to use some time of timer for the game. Additionally, keep in mind that the whole script is quite CPU intensive because it will run (or at least try to) every frame. If you intend to use it on specifically limited occurencies it could be quite OK, but it should be avoided as an often-called script.

 

The script doesn't seem to cope well with multiplayer or in situations where many players are inside the vehicle of interest. A more "sophisticated" solution should be implemented for such cases. Nevertheless, this solution may (or may not) provide a starting point for a possible (and hopefully) better solution.

 

Finally, please keep in mind that these scripts are NOT tested and should be treated with caution.

 

I hope this helped somehow. If not, or if you have more questions please don't hesitate to ask.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×