Jump to content
Sign in to follow this  
ange1u5

Help moving aircraft and their waypoints...

Recommended Posts

I've been tring to move some aircraft and their waypoints based on certain mission parameters the player chooses on startup. Its just two A-164's which are grouped that fly over on the mission start then just follow a series of waypoints. I've attempted to use this code:

{ _x enablesimulation false; } foreach group plane1

plane1 setPos (MarkerPos "c2plane1");
plane2 setPos (MarkerPos "c2plane2");

{ _x enablesimulation true; } foreach group plane1


[group plane1, 1] setWPPos (markerPos "c2wp1");
[group plane1, 2] setWPPos (markerPos "c2wp2");
[group plane1, 3] setWPPos (markerPos "c2wp3");
[group plane1, 4] setWPPos (markerPos "c2wp4");
[group plane1, 5] setWPPos (markerPos "c2wp5");
[group plane1, 6] setWPPos (markerPos "c2wp6");
[group plane1, 7] setWPPos (markerPos "c2wp7");

Nothing seems to happen and in fact breaks the SQF file it goes into (which moves other objects in the mission).

Any and all help appreciated :)

Edited by ange1u5

Share this post


Link to post
Share on other sites

{ _x enablesimulation true; } foreach group plane1 there is no ; at the and of the line

{ _x enablesimulation true; } foreach group plane1;

Share this post


Link to post
Share on other sites

Has made no difference I'm afraid, the code is still not executing properly. When I place the code at the beginning of this SQF its in, anything below it doesn't work so its getting stuck somewhere.

Share this post


Link to post
Share on other sites

You need to run the forEach on the units of the group.

Try this:

{_x enablesimulation false} forEach (units group plane1);

plane1 setPos (MarkerPos "c2plane1");
plane2 setPos (MarkerPos "c2plane2");

{_x enablesimulation true} forEach (units group plane1);


[group plane1, 1] setWPPos (markerPos "c2wp1");
[group plane1, 2] setWPPos (markerPos "c2wp2");
[group plane1, 3] setWPPos (markerPos "c2wp3");
[group plane1, 4] setWPPos (markerPos "c2wp4");
[group plane1, 5] setWPPos (markerPos "c2wp5");
[group plane1, 6] setWPPos (markerPos "c2wp6");
[group plane1, 7] setWPPos (markerPos "c2wp7");

Share this post


Link to post
Share on other sites

Great that works! However the planes are now spawning on the ground and there's no altitude to set for a marker position. I'm guessing getPosATL/setPosATL is the key there, but not sure what order it needs to be in for the code :(

Edited by ange1u5

Share this post


Link to post
Share on other sites

Cool, okay you're on the right track with setPosATL.

What I would do (not knowing how you want to set the mission up) is modify the code in here so you can still use the markers.

When you get a position off a marker it's in a 2D format [x,y] (check the Wiki) :)

Then you can create a new array and put the Z position in it (so the planes move up into the air). Try something like this:

// create a local var from the marker pos

_mkrPos1 = markerPos "c2plane1";

// then use the select command to extract the elements from the array and build a new one with the desired Z position included

_spawnPos1 = [_mkrPos1 select 0, _mkrPos1 select 1, 1000];

// then use the new array as the setPos position for the starting place
// you could use either setPos or setPosATL as they do the simlar things but setPosATL 
// is more efficient (unless you're over water in which case use setPos as it returns the 
// height relative to the surface)

plane1 setPosATL _spawnPos1;

Edit the 1000 to whatever height you need. Repeat that for plane 2 and you should be golden. Untested of course!

There are more efficient ways to do this but I wanted to lay it out in a format that hopefully explains what's going on.

Hope that helps you.

Share this post


Link to post
Share on other sites

So basically should end up looking like this?

{_x enablesimulation false} forEach (units group plane1); 


_mkrPos1 = markerPos "c2plane1";
_spawnPos1 = [_mkrPos1 select 0, _mkrPos1 select 1, 1000];
plane1 setPosATL _spawnPos1;  

_mkrPos1 = markerPos "c2plane2";
_spawnPos1 = [_mkrPos1 select 0, _mkrPos1 select 1, 1000];
plane2 setPosATL _spawnPos1;  

{_x enablesimulation true} forEach (units group plane1); 


[group plane1, 1] setWPPos (markerPos "c2wp1"); 
[group plane1, 2] setWPPos (markerPos "c2wp2"); 
[group plane1, 3] setWPPos (markerPos "c2wp3"); 
[group plane1, 4] setWPPos (markerPos "c2wp4"); 
[group plane1, 5] setWPPos (markerPos "c2wp5"); 
[group plane1, 6] setWPPos (markerPos "c2wp6"); 
[group plane1, 7] setWPPos (markerPos "c2wp7");  

Share this post


Link to post
Share on other sites

That should work - give it a go and let me know - if it works, we can look at some other cool stuff to do that makes your life easier when you're scripting and gives you more control over what's going on.

Share this post


Link to post
Share on other sites

Yep it works :D

Though it looks like they're starting from 0 speed because they nosedive sharply before gaining speed to level off!

Share this post


Link to post
Share on other sites

Glad that's working okay.

There's two ways we could go at this point; one of which has nothing to do with using markers so we can get rid of some of the code, and the other is a continuation of how you are doing it at the moment but can get quite complex.

Before we start going off at a tangent though, what position are the two planes facing in the editor?

We could add some velocity just after they have been setPos'd so they don't dive.

Share this post


Link to post
Share on other sites

Wow looks like you spent quite a bit of time on this one!

What you could try is editing the planes and setting their "special" tab to "flying". That might work.

Or use the addVelocity command in your script just after the setPosATL command:

_mkrPos1 = markerPos "c2plane1"; 
_spawnPos1 = [_mkrPos1 select 0, _mkrPos1 select 1, 1000]; 
plane1 setPosATL _spawnPos1;
plane1 setVelocity [80,400,0]; // just a guess, this may be wrong!!!!!!

You should read up on the simulation manager - it may well help manage performance with all those objects on the map.

Share this post


Link to post
Share on other sites

A bit of time is an understatement :P

Its this mission here. Currently on v1.5 where its just a single race. But now with help I've been learning how to setup a parameter to move all appropriate objects to other locations allowing me to make a multi-course race. I'm aiming to create 6 variations of my Highway Race to make it more interesting and replayable. This is why the map looks so dense with things :P

I will try the velocity code out and let you know :) Also will look into the simulation manager too!

Edited by ange1u5

Share this post


Link to post
Share on other sites

If the planes spawn in the bottom left corner then it's probably alright. I noticed though that you have markers in the bottom right hand corner of the map so if they are where the planes are moved to then you'll need to use some other values.

Share this post


Link to post
Share on other sites

SetVelocity works too though I need to tweak the numbers, the planes are more or less doing what I want them to right now. Thanks again :)

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  

×