Jump to content
Sign in to follow this  
igneous01

Move a collection of objects with proportion to another

Recommended Posts

I have a slight problem with one of my scripts that I have run into. Its more a mathematical problem as I forgot how to do this.

I want to have 4 game logics organised in a line in front of my player, and to move these objects with the player, with relation to each other, and to have the direction be the same as the player as well.

So imagine a line of boxes that move around in a circle around the player when he rotates or changes his direction.

this is what I have so far:

if ((_PlatoonCmd distance _x) < 20) then {	
       		_x setpos [(getpos _PlatoonCmd select 0) + ((sin (getdir _PlatoonCmd)) * 20) + (_larray select _t),  (getpos _PlatoonCmd select 1) + ((cos (getdir _PlatoonCmd)) * 20) + (_larray select _t + 1), getpos _PlatoonCmd select 2];
	};
	if ((_PlatoonCmd distance _x) > 120) then {	
       		_x setpos [(getpos _PlatoonCmd select 0) + ((sin (getdir _PlatoonCmd)) * 20) + (_larray select _t),  (getpos _PlatoonCmd select 1) + ((cos (getdir _PlatoonCmd)) * 20) + (_larray select _t + 1), getpos _PlatoonCmd select 2];
	};
	_t = _t + 1;

	if (_t > (count _larray)) then {
		_t = 0;
	};

} foreach _logics;

I have direction and distance between the objects and player, but I dont have them positioned relative to each other in a uniform line.

If anyone knows how this is done, I could really use some advice.

Thanks

Share this post


Link to post
Share on other sites

Shuko to the rescue:

http://derfel.org/arma2/scripts/SHK_moveobjects.sqf

Upon a second reading it looks like you want to have the items move AS the player moves, not just move to the players new location? AttachTo would probably work for that. Or rip apart R3F's cargo scripts and see how they do the moving of things maybe.

Share this post


Link to post
Share on other sites

yes, I kind of need the logics to move in real time with the player (update maybe every couple seconds) as I want to use them as slots for formations, so that I its easier for the squads to move and follow their respected game logic to stay in formation.

I will have a look at attachto again, been fiddling around with shk_moveobjects, but it keeps setpos them to the end of the map [0,0,0] instead of revolving around the player.

Share this post


Link to post
Share on other sites

if attachTO is not what you need/want then try this:

here is a function i used to spawn various things in relation to a object and objects direction, for example front of object, or right side.

where i got the code from is unknown, its a long time since, but a very useful code.

It have served me well.

_relativePosition = {
_leadVehicle = _this select 0;  // the object another object is offset from.
_offdir = _this select 1; // direction for newPos in relation to leadvehicle, 0 is direct front, 90 right, 180 rear etc..
_dist = _this select 2;  // distance from center of _leadVEhicle to its ofset position.

//find position to spawn in relation to.
_planePos = getPos _leadVehicle;

//Find compass direction to spawn from leader plane.
_compassDir = ((getDir _leadVehicle)+_offdir) mod 360;

//Find absolute coordinates by adding relative to leader plane.
_newX = (_planePos select 0) + (sin _compassDir * _dist);
_newY = (_planePos select 1) + (cos _compassDir * _dist);
_newZ = (_planePos select 2);
_newPos = [_newX, _newY, _newZ];
_newPos
};	

simply add to or hardcode distance and directions in a loop or foreach command like this:

while {true} do {
_dist = 0;
_offDir = 0;
_leadVehicle = player;
{
	_dist = _dist + 10;  // lets add 10 spacing inbetween each object wich is placed in a direct line front of player no matter where he is looking.
	_newPos = [(vehicle player),_offDir,_dist] call _relativePosition; 
	_x setPos _newPos;
} foreach [obj1,obj2,obj3,obj4,obj5];
sleep 0.01;
};

Share this post


Link to post
Share on other sites

I tried attachto, and it looks beautiful because of the free rotation and instant position update, sadly, the attached objects position is bugged out, as my squads will charge past their respective formation slots, and proceed to running around in circles.

However the script you posted Demonized works great! Now I can finally have my squads move in a large formation with me :D

thanks for the help, If i run into some trouble I will post back

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  

×