Jump to content
3LGStevo

Player Vehicle - Force Brake

Recommended Posts

I need a way to force a player vehicle to brake via script without using SetVelocity.

I've tried to use keyHandler which de-presses the W key when the criteria is met by returning True, but this then means the vehicle can't accelerate again unless the key is lifted, and pressed again... while it's not an ideal solution to use this handler, it is the most effective way of slowing a player's vehicle based on a trigger from what I've found so far.

So my questions are simple;

  • Are there any possible methods where you can force a player's key press (i.e. in this Scenario, force a keypress event for "S")?
  • Is there a way to configure the KeyHandler so that it continues on with keypresses after the "true" handle is triggered?

Share this post


Link to post
Share on other sites

How comes you cant use setVelocity?

Also try teleporting the player to the players position, 

_vPos = getpos (vehicle player);

(vehicle player) setpos _vPos;

It's only just an idea I'm not sure if itll work 

Share this post


Link to post
Share on other sites
1 hour ago, bumyplum said:

How comes you cant use setVelocity?

Also try teleporting the player to the players position, 

_vPos = getpos (vehicle player);

(vehicle player) setpos _vPos;

It's only just an idea I'm not sure if itll work 

 

Both SetPos and SetVelocity are jittery as hell... and that's just on a singleplayer client.
As soon as you add in any kind of MP element, it's going to be entirely unreliable and just add a heap of bugs on it's functionality.

The ability to force a vehicle to apply its brakes with a player driving is the only viable workaround where the engine handles the vehicles ability to slowdown where the trigger occurs... sadly bohemia haven't added that functionality via a simple scripting command, or the ability to press a key for a player (as far as I can tell). The KeyHandler was a stroke of genius, but as soon as the "true" is passed, the repetitive keystroke no longer occurs so it basically forces the player to remove their finger from the W key, and re-press it again to continue driving (which kind of defeats the object if I'm forcing the player to remove their finger from W, otherwise they'd just do it themselves anyway).

Share this post


Link to post
Share on other sites

@3LGStevo,

What about limitSpeed?

aCAR limitSpeed 100;

to brake,

aCAR limitSpeed 50;
sleep 3;
aCAR limitSpeed 20;
sleep 2:

aCAR engineOn false;
aCAR enableSimulation false;

It's not a pretty script but it looks like braking and stopping.

Or, just very simply,

aCAR limitSpeed 0;

Have fun!

Share this post


Link to post
Share on other sites

You can also use setVelocityModelSpace in a loop.  I did this in my mission Razing Cane, where I had a chase sequence where I decelerated player driven vehicle when it got too close to vehicle it was chasing (it was important to plot to not allow chased vehicle to be ran off the road.  Within a onEachFrame loop, I would use this to incrementally reduce player vehicle speed.   It worked quite well.

  • Like 2

Share this post


Link to post
Share on other sites

You can play with fuel set to zero then refilled along with frames (EH). It's a little bit tricky but I didn't find better for limiting the player's vehicle speed. Not on Arma. Sorry for no more details.

  • Like 1

Share this post


Link to post
Share on other sites
22 hours ago, wogz187 said:

@3LGStevo,

What about limitSpeed?


aCAR limitSpeed 100;

to brake,


aCAR limitSpeed 50;
sleep 3;
aCAR limitSpeed 20;
sleep 2:

aCAR engineOn false;
aCAR enableSimulation false;

It's not a pretty script but it looks like braking and stopping.

Or, just very simply,


aCAR limitSpeed 0;

Have fun!


limitSpeed doesn't work on player vehicles. I already tried this, and inside a loop to repeatedly force the "speed limit"... unfortunately nothing happened at all.
 

21 hours ago, johnnyboy said:

You can also use setVelocityModelSpace in a loop.  I did this in my mission Razing Cane, where I had a chase sequence where I decelerated player driven vehicle when it got too close to vehicle it was chasing (it was important to plot to not allow chased vehicle to be ran off the road.  Within a onEachFrame loop, I would use this to incrementally reduce player vehicle speed.   It worked quite well.


Again, unfortunately setVelocity and setVelocityModelSpace is jittery as hell, even simply in 3DEN, solo... with this command over a multiplayer environment, it's going to send desyncs through the roof and constant issues with multiple clients sat in the same vehicle.
 

5 hours ago, pierremgi said:

You can play with fuel set to zero then refilled along with frames (EH). It's a little bit tricky but I didn't find better for limiting the player's vehicle speed. Not on Arma. Sorry for no more details.


Yup, already tried fuel, engine, wheels... everything with regards to damaging and removing the fuel. It sounds horrific though and when the trigger stops, there's a slight chance that it renders the vehicle without any fuel while exiting the script because initial trigger loop is still running when the trigger exits - definitely not an ideal scenario.

The best solution by far is the KeyHandler event, however, I need to find a way so that when the keyHandler returns handled, that the keypress still triggers when being held-down.

Share this post


Link to post
Share on other sites

@3LGStevo,
 

Quote

limitSpeed doesn't work on player vehicles.

I missed the part about it being "Player vehicle".
 

Quote

there's a slight chance that it renders the vehicle without any fuel while exiting the script because initial trigger loop is still running when the trigger exits

You could record the fuel state as a variable before altering it and then return to the recorded fuel state after your event.

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, 3LGStevo said:

Again, unfortunately setVelocity and setVelocityModelSpace is jittery as hell, even simply in 3DEN, solo... with this command over a multiplayer environment, it's going to send desyncs through the roof and constant issues with multiple clients sat in the same vehicle.

It worked smooth for me by reducing speed by tiny fraction incrementally (in SP).  No idea how that would be in MP.  This may not work for you, but maybe it will help someone else with similar question.  Good luck.

This code was executed onEachFrame:

            if (speed _chaseVehicle > 80 and _veh distance _chaseVehicle < 60 and !JBOY_SKEY_DOWN) then
            {
				_forwardY = velocityModelSpace _chaseVehicle select 1;
				_chaseVehicle setVelocityModelSpace [0, _forwardY *.98, 0];  // decelerate incrementally 
            };

 

  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, 3LGStevo said:


limitSpeed doesn't work on player vehicles. I already tried this, and inside a loop to repeatedly force the "speed limit"... unfortunately nothing happened at all.
 


Again, unfortunately setVelocity and setVelocityModelSpace is jittery as hell, even simply in 3DEN, solo... with this command over a multiplayer environment, it's going to send desyncs through the roof and constant issues with multiple clients sat in the same vehicle.
 


Yup, already tried fuel, engine, wheels... everything with regards to damaging and removing the fuel. It sounds horrific though and when the trigger stops, there's a slight chance that it renders the vehicle without any fuel while exiting the script because initial trigger loop is still running when the trigger exits - definitely not an ideal scenario.

The best solution by far is the KeyHandler event, however, I need to find a way so that when the keyHandler returns handled, that the keypress still triggers when being held-down.

 

 

No trigger at all but on each frame Event Handler. Trigger : 2 possible slots running a code, this EH: 30 events/ sec if 30 FPS

Share this post


Link to post
Share on other sites
18 hours ago, 3LGStevo said:

Again, unfortunately setVelocity and setVelocityModelSpace is jittery as hell, even simply in 3DEN, solo... with this command over a multiplayer environment, it's going to send desyncs through the roof and constant issues with multiple clients sat in the same vehicle.

ACE is using that for its vehicle speed limiter, and it works fine there.

Share this post


Link to post
Share on other sites
On 9/17/2019 at 5:14 PM, johnnyboy said:

It worked smooth for me by reducing speed by tiny fraction incrementally (in SP).  No idea how that would be in MP.  This may not work for you, but maybe it will help someone else with similar question.  Good luck.

This code was executed onEachFrame:


            if (speed _chaseVehicle > 80 and _veh distance _chaseVehicle < 60 and !JBOY_SKEY_DOWN) then
            {
				_forwardY = velocityModelSpace _chaseVehicle select 1;
				_chaseVehicle setVelocityModelSpace [0, _forwardY *.98, 0];  // decelerate incrementally 
            };

 

 

I've gone with something similar to this... it's still not ideal, as it's quite jittery, but I guess it will have to do.

Thanks all.

  • Like 1

Share this post


Link to post
Share on other sites
On 9/17/2019 at 6:14 PM, johnnyboy said:

It worked smooth for me by reducing speed by tiny fraction incrementally (in SP).  No idea how that would be in MP.  This may not work for you, but maybe it will help someone else with similar question.  Good luck.

This code was executed onEachFrame:


            if (speed _chaseVehicle > 80 and _veh distance _chaseVehicle < 60 and !JBOY_SKEY_DOWN) then
            {
				_forwardY = velocityModelSpace _chaseVehicle select 1;
				_chaseVehicle setVelocityModelSpace [0, _forwardY *.98, 0];  // decelerate incrementally 
            };

 

:icon_dj:

I'm gonna use that for simulating an arrest-wire on the carrier when you land planes without tailhook.....thanks, man!!!

 

ps: this will do, right?



if (speed CAS_plane > 80) then
            {
				_forwardY = velocityModelSpace CAS_plane select 1;
				CAS_plane setVelocityModelSpace [0, _forwardY *.98, 0];  // decelerate incrementally 
            };

 

Share this post


Link to post
Share on other sites
1 hour ago, zagor64bz said:

ps: this will do, right?

It should.  You can modify the .98 value to decrease speed faster or slower to find what works best for you.  Saw your vid and dug the ai landing with tail hook.  Very cool.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks, bud. Actually, a very easy thing to do indeed...

For anyone coming here for an answer:

_dynamicAirport1 = "DynamicAirport_01_F" createVehicle position this;//// put this on the carrier init 
CAP landAt _dynamicAirport1;///this also in the init, where CAP is the plane variable name 

Ps: it did work actually...

if (speed vehicle player >= 100) then { 
    _forwardY = velocityModelSpace vehicle player select 1; 
    vehicle player setVelocityModelSpace [0, _forwardY *.98, 0];   
            };

 

  • Like 3

Share this post


Link to post
Share on other sites

FYI, the alterations needed to maintain a vehicle that's also increasing/decreasing altitude (even vehicles on Terrain going up and down) means you also need to preserve the X and Z references, not set them to 0.

SUV for example, will start to take off if you use the simple modification of Y with setVelocityModelSpace.

I just did the below inside an addAction to bypass the whole trigger scenario.
The - 0.2 aspect I found to be more consistent than multiplying by a decimal, and it seemed more realistic for vehicle braking.

life_limiting_speed = true;
life_speed_limit = speed (vehicle player);
["speedLimiter","onEachFrame",{
	if (speed (vehicle player) > (life_speed_limit + 0.5)) then {
		_VM = velocityModelSpace (vehicle player);
		(vehicle player) setVelocityModelSpace [(_VM select 0),((_VM select 1) - 0.2),(_VM select 2)];
	};
}] call bis_fnc_addStackedEventHandler;

 

  • Like 2

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

×