Jump to content
Sign in to follow this  
This kid

Using the "forceSpeed" command on helicopters

Recommended Posts

I'm making a mission where I need the helicopter to fly really slowly while the player shoot at some difficult targets. When giving the helicopter waypoints I can set the speed to "Limited", I know, but even this is to fast.

So I try using the forceSpeed command:

heli1 forceSpeed 1

...which, as I understand it, should give the helicopter heli1 a speedlimit of 1 m/s. (meters per second)

I've tried this command in the activation field in waypoints and even in the initialization field, but with no luck.

When testing this I used a clean map with no enemy units to trigger any micro AI behaviour that might override the waypoint commands. Still didn't work. I tried the same on a Humvee and then it worked just fine.

Any suggestions?

Edited by This kid
corrected spelling

Share this post


Link to post
Share on other sites

You're quite right - forceSpeed doesn't work on helicopters.

However, limitSpeed partially works (it only works for an instant) - so here's a "decent-ish" solution, that will run from the init line of the chopper. It does cause the chopper to 'bob' ever so slightly, but it's still fine for shooting from.

this setVariable ["limitSpeed",5];
0=[this] spawn {
while {canMove (_this select 0) } do {
	(_this select 0) limitSpeed ((_this select 0) getVariable "limitSpeed");
	sleep 0.1;
};
};

Then, to change the speed, just do:

<chopperName> setVariable ["limitSpeed", 10];

Edited by JamesF1

Share this post


Link to post
Share on other sites

Thanks for your reply.

I copied and pasted your code in to the helicopter's init field but the editor would not accept it. :confused:

I got a big box with an OK-button on it, but with no error message. It is the same box that usually say something like "missing ;" or stuff like that.

Could there be some small typo somewhere? Sadly, I am not competent enough in the field of scripting to see any typos my self.

Share this post


Link to post
Share on other sites

Yup, there was a small error - but I've fixed it in the sample above now :)

Share this post


Link to post
Share on other sites

I copied and pasted your revised code and ... IT WORKS! :yay:

The bobbing is very small. Will not be a problem. Thank you very much! :)

While trying out other solutions to the problem I experimented with setAccTime. Using the value 0.6 gives the desired result as well. Of course, setAccTime makes EVERYTHING slow down. Your solution is by far the best.

Thank you!

Share this post


Link to post
Share on other sites
You're quite right - forceSpeed doesn't work on helicopters.

However, limitSpeed partially works (it only works for an instant) - so here's a "decent-ish" solution, that will run from the init line of the chopper. It does cause the chopper to 'bob' ever so slightly, but it's still fine for shooting from.

this setVariable ["limitSpeed",5];
0=[this] spawn {
while {canMove (_this select 0) } do {
	(_this select 0) limitSpeed ((_this select 0) getVariable "limitSpeed");
	sleep 0.1;
};
};

Then, to change the speed, just do:

<chopperName> setVariable ["limitSpeed", 10];

I used this and it worked!

Share this post


Link to post
Share on other sites
;1844073']Why do you use _this select 0 instead of _this (or even this)?

Isn't _this already the object needed for limitSpeed?

I don't know the answer I just copy'd/paste'd but I am curious as well.

Share this post


Link to post
Share on other sites

Well, the thing before "spawn" gets passed as _this to the following code-block, no matter what this is. Here we have:

[_object] spawn {
  //...
};

(ok, in your code you pass [this], but this is an object, so...)

Thus, you pass an array with one object to the spawn's code-block. Exactly that array is now accessible with "_this". And since you packed your object into an array, you have to write (_this select 0) to get that object again.

You could simplify things, if you would write it like this:

this setVariable ["limitSpeed",5];
0 = this spawn {
while {canMove _this } do {
	_this limitSpeed (_this getVariable "limitSpeed");
	sleep 0.1;
};
};

Now only the object gets passed along, thus _this refers to that object, so there is no need anymore to pull it out from any array.

One usually passes an array to spawn (or some function), so that one may pass along more stuff, maybe at some later point... But if you're sure you're really going to pass only one object along, well, then don't put it in an array.

Share this post


Link to post
Share on other sites
Well, the thing before "spawn" gets passed as _this to the following code-block, no matter what this is. Here we have:

[_object] spawn {
  //...
};

(ok, in your code you pass [this], but this is an object, so...)

Thus, you pass an array with one object to the spawn's code-block. Exactly that array is now accessible with "_this". And since you packed your object into an array, you have to write (_this select 0) to get that object again.

You could simplify things, if you would write it like this:

this setVariable ["limitSpeed",5];
0 = this spawn {
while {canMove _this } do {
	_this limitSpeed (_this getVariable "limitSpeed");
	sleep 0.1;
};
};

Now only the object gets passed along, thus _this refers to that object, so there is no need anymore to pull it out from any array.

One usually passes an array to spawn (or some function), so that one may pass along more stuff, maybe at some later point... But if you're sure you're really going to pass only one object along, well, then don't put it in an array.

ruebe, thanks for the explanation and you are much more advanced than I. When I get back from Philly, I will try your code and see if that works as well.

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
Sign in to follow this  

×