Jump to content
sarogahtyp

Slow down a vehicle permanently

Recommended Posts

Hey guys,

 

I'm currently writing a script with a feature for vehicles which should have huge energy consumption. Let's say it is a lamp which shines as bright as the sun ;-)

If that thing is enabled it should have a noticable effect on the energy consumption of the vehicle and vehicles enginge shoul have to work much more against the forces of the energy generator as if the lamp is disabled. Therefore I need a possibility to slow down the vehicle if the lamp is enabled.

 

What I need is a hint on how I could simulate such vehicle slow down. Maybe you have some thoughts bout it....

 

EDIT: I would be happy with a solution for landvehicles at first but my aim is to to it for all vehicle types.

Share this post


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

got a hint on discord chat. it should work with:

 

setMass

 

I ll try it and feedback.

 

I tried setmass a while ago to slow down civilian vehicles near the player, but gave up on the idea. Greatly increasing the car's mass greatly certainly slows it down, but the car cannot be driven very well by AI or player because it has hugely increased inertia through corners and when braking. YMMV of course!

Share this post


Link to post
Share on other sites

Like tpw said, setMass has weird effects on vehicles, can't really steer them if their mass increases above a certain percentage.

Your best bet would be to use setVelocityModelspace, but there's no elegant implementation as far as I'm aware, since using it on every frame will basically reset the velocity vector making it an odd experience,

using it every .n seconds makes for a choppy experience.

 

Try this and go from there, makes it impossible to accelerate past 30 while still being able to somewhat steer the vehicle.

 

YourVariable = true;
onEachFrame {

	_veh = vehicle player;
	_v = velocityModelSpace _veh;
	_v params ["_dir","_fwd","_imaneagle"];

	if (speed _veh >= 30 AND YourVariable) then {

		_v set [1,_fwd * 0.9];
		_veh setVelocityModelSpace _v;

	};
	
};

 

Hopefully some script commands will come where you can manipulate a vehicles engine power output/torque but as for now there's no smooth way that I know of.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Grumpy Old Man said:

Like tpw said, setMass has weird effects on vehicles, can't really steer them if their mass increases above a certain percentage.

Your best bet would be to use setVelocityModelspace, but there's no elegant implementation as far as I'm aware, since using it on every frame will basically reset the velocity vector making it an odd experience,

using it every .n seconds makes for a choppy experience.

 

Try this and go from there, makes it impossible to accelerate past 30 while still being able to somewhat steer the vehicle.

 


YourVariable = true;
onEachFrame {

	_veh = vehicle player;
	_v = velocityModelSpace _veh;
	_v params ["_dir","_fwd","_imaneagle"];

	if (speed _veh >= 30 AND YourVariable) then {

		_v set [1,_fwd * 0.9];
		_veh setVelocityModelSpace _v;

	};
	
};

 

Hopefully some script commands will come where you can manipulate a vehicles engine power output/torque but as for now there's no smooth way that I know of.

 

Cheers

 

Okay, thank u for that snippet. I ll use it and just raise it's limit (30 km/h) slowly to get a acceleration handicap simulated if I can't use the setMass way.

Share this post


Link to post
Share on other sites

setMass worked for me. Steering is not such bad with 200% mass but actually I tested a tank only.

sent from mobile using Tapatalk

Share this post


Link to post
Share on other sites

hm...just a ridicolous idea, not tested:
setfuel 0;
sleep 1;
setfuel 1;
sleep 1;
setfuel 0;
....and so on....

Share this post


Link to post
Share on other sites

was so ridicolous that i had to try it, lol!
 


   while {true} do {
       car1 setfuel 0;
       sleep 0.5;
       car1 setfuel 1;
       sleep 0.5;       
   };

seems to work with ground vehicles and airplanes, sadly not for helicopters.
anyway every type of vehicle needs its own settings...for example that are good for the "SUV" civ vehicle, while a tank needs a 1.5 fuel 1 and 0.5 fuel 0.....
 

Share this post


Link to post
Share on other sites

Hmm... and how do I explain the driver that the vehicle he is driving has sometimes full fuel and sometimes it is empty? :D

Share this post


Link to post
Share on other sites

Call the car car1 and paste this in debug console:  (Do it when the car is stationary or it may flip).

 

onEachFrame { 
 _vel = velocity car1; 
 _vel = _vel apply {_x * -1}; 
 _vel = _vel vectorMultiply 50; 
 car1 addForce [_vel,[0,0,0]]; 
};

 

Makes a hunter travel at 28kph tops.  Play with the numbers but it should work,

  • Like 2

Share this post


Link to post
Share on other sites

I read bout addforce but didn't try it yet... Thx

sent from mobile using Tapatalk

Share this post


Link to post
Share on other sites

Cool cool  :)

 

It might be worth putting a cutoff velocity and also checking to see if the car is on the ground (or it may float in the air if it goes off a cliff)

 

Like:

 

onEachFrame {
    _vel = velocity car1;
    if (vectorMagnitude _vel > 4 and {isTouchingGround car1}) then {
        _vel = _vel apply {_x * -1};
        _vel = _vel vectorMultiply 50;
        car1 addForce [_vel,[0,0,0]];
    };
};

 

  • Like 3

Share this post


Link to post
Share on other sites

Yeah good thing. I think a canmove check couldn't hurt as well in the case it or its engine gets destroyed. With those checks it could be applied to helis and planes as well I guess

sent from mobile using Tapatalk

Share this post


Link to post
Share on other sites

Kinda ridiculous to not have a command which simply limits the vehicle's speed, and then folks are wondering why the performance of the game might be bad if things like that run on each frame.

 

*I know, not very helpful, but had to post that.

  • Like 1

Share this post


Link to post
Share on other sites

Really? For AIs:

this limitSpeed 20;  (km/h) no need to loop.

  • Like 1

Share this post


Link to post
Share on other sites

But imagine a command that sets the maximum speed of a vehicle even for players. Like a tank with 300km/h. Wouldn't that be amazing?

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, 7erra said:

But imagine a command that sets the maximum speed of a vehicle even for players. Like a tank with 300km/h. Wouldn't that be amazing?

We better get writing to Santa..

Share this post


Link to post
Share on other sites

At least, players can run very fast:

player setAnimSpeedCoef 10

Share this post


Link to post
Share on other sites

@R3vo
It is helpful because it gets me back on ground and thinking more about performance.
Would a solution with a while loop and a sleep 0.5 a better solution for it?
I don't want to have a huge performance impact with this. Maybe I should just go with setMass instead...

sent from mobile using Tapatalk
 

Share this post


Link to post
Share on other sites
10 minutes ago, sarogahtyp said:

@R3vo
It is helpful because it gets me back on ground and thinking more about performance.
Would a solution with a while loop and a sleep 0.5 a better solution for it?
I don't want to have a huge performance impact with this. Maybe I should just go with setMass instead...

sent from mobile using Tapatalk
 

 

Do you really need something for players in vehicle?

Share this post


Link to post
Share on other sites

Yes. It's a cloaking system which gives a huge advantage and therefore it should have a handicap like a reduced engine performance.

sent from mobile using Tapatalk

  • Like 1

Share this post


Link to post
Share on other sites

If you don't want onEachFrame (which isn't bad performance-wise imo as long as it's for a few vehicles), then you could damage the tyres.

 

{vehicle player setHitPointDamage[_x,0.98]} forEach ["HitLFWheel","HitLF2Wheel","HitRFWheel","HitRF2Wheel"];

 

On a hunter reduces speed to 16kph

 

Only downside is the tyres are incredibly knackered (obv).  I guess you could add a handleDamage EH to manage any further knocks to them.  Up to you though.

  • Like 1

Share this post


Link to post
Share on other sites
On ‎28‎/‎07‎/‎2017 at 3:33 PM, sarogahtyp said:

Hmm... and how do I explain the driver that the vehicle he is driving has sometimes full fuel and sometimes it is empty? :D

 

You could say that using the powerful light will cause a reduction in power and some fluctuation of the vehicle's instrumentation display.     ;)

  • Like 1

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

×