Jump to content
Sign in to follow this  
braincrush

moving object (not unit)

Recommended Posts

Hi buddy....hope this helps you.

This script moves the object wsold1 (the object can be anything) from marker1 to marker2 in 0.1m steps....pausing for 0.2 seconds between steps.

Change the object, markers, steps and timing to suit.

Place the markers "marker1" and "marker2" some distance apart.

Place wsold1 anywhere...he will be at the start position (marker1) when the script runs.

Execute the code like this:-

nul = [wsold1,"marker1","marker2",0.1,0.2] execVM "move_obj.sqf";

The script itself:-

"move_obj.sqf"

private ["_obj","_mkr1","_mkr2","_step","_timg","_x","_y","_i","_dis","_dir"];

_obj = _this select 0;
_mkr1 = _this select 1;
_mkr2 = _this select 2;
_step = _this select 3;
_timg = _this select 4;

_obj setPos getMarkerPos _mkr1;				//sets the object to the first marker position

_x = ((getMarkerPos _mkr2 select 0)-(getMarkerPos _mkr1 select 0));
_y = ((getMarkerPos _mkr2 select 1)-(getMarkerPos _mkr1 select 1));

//trig
_dir = _x atan2 _y;
if (_dir < 0) then {_dir = _dir+360};		//direction from mkr1 to mkr2

//pythagoras
_dis = sqrt(_x^2+_y^2);						//distance from mkr1 to mkr2

for [{_i=0},{_i<_dis},{_i=_i+_step}] do {
_x = sin(_dir)*_i;
_y = cos(_dir)*_i;
_obj setPos [(getMarkerPos _mkr1 select 0) + _x,(getMarkerPos _mkr1 select 1) + _y,0];
sleep _timg;
};

There's a little test done on Utes here for you.

http://www.mediafire.com/file/ggg7kquuub1mpfa/AA_Test_Move_Target.utes.zip

If you have trouble...post again.

Edited by twirly
Clarity

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  

×