Jump to content
Sign in to follow this  
evans d [16aa]

How to Make Targets Scroll Side to Side.

Recommended Posts

Heya guys, trying to make a shooting range and to make it more challenging I want some of the targets to move side to side like they do in the armoury and at the beginning of Red Harvest.

Waypoints don't work, and that's pretty much the limit of my knowlage.

I might be going to the wrong place, of course. I'm going to Empty > Targets > Target (small)

Is there maybe a "living" target that accepts waypoints rather than an "empty" one?

Cheers!

Share this post


Link to post
Share on other sites

From the bootcamp missions:

//--------------------------------------------------------------------------------------------------

// SHOOTING: AT MOVING TARGETS

//--------------------------------------------------------------------------------------------------

[bIS_SniperTarget_2,BIS_SniperTarget_1,1,1.8] call BIS_execMovingTarget;

[bIS_SniperTarget_4,BIS_SniperTarget_3,1,2.1] call BIS_execMovingTarget;

[bIS_SniperTarget_6,BIS_SniperTarget_5,0.7,2.0] call BIS_execMovingTarget;

BIS_execMovingTarget = {

private["_start","_end","_distance","_hoverHeight","_i","_pos","_posStart","_posEnd","_fsm","_t","_threads"];

//init

_start = _this select 0;

_end = _this select 1;

_speed = _this select 2;

_hoverHeight = _this select 3;

BIS_ShootingCompleted = false;

BIS_ShootingFailed = false;

//show the path

_distance = round (_start distance _end);

_end setPosASL ([_start,_end,_distance] call BIS_getPosInDistance);

//re-position the start & end marker

_posStart = getPos _start;

_posStart = [_posStart select 0, _posStart select 1, _hoverHeight - 0.05];

_posEnd = getPos _end;

_posEnd = [_posEnd select 0, _posEnd select 1, _hoverHeight - 0.05];

_start setPos _posStart;

_end setPos _posEnd;

//create target

_dir = [_start,player] call BIS_fnc_dirTo;

BIS_GTarget = "TargetEpopup" createVehicle _posStart;

BIS_GTarget setDir _dir;

BIS_GTarget setPos [_pos select 0,_pos select 1,_hoverHeight];

//add a handler

BIS_GTarget addEventHandler ["HandleDamage", "_this call BIS_handler_SniperTargetHit2"];

BIS_GTarget allowDamage true;

//init target icon

BIS_GTarget call BIS_targetIconInit;

//display icon

BIS_GTarget spawn BIS_targetIconShow;

//update icon text

BIS_Thread_UpdateIconText = [] spawn {

[bIS_GTarget, format["%1 m",round(player distance BIS_GTarget)]] call BIS_targetIconUpdateText;

while {!BIS_ShootingCompleted} do {

_state = BIS_GTarget getVariable "icon_state";

//update text only if icon is shown (not showing or hidding or hidden)

if (_state == "shown") then {

[bIS_GTarget, format["%1 m",round(player distance BIS_GTarget)]] call BIS_targetIconUpdateText;

};

sleep 0.5;

};

//["THREAD FINISHED","BIS_Thread_UpdateIconText"] call BIS_debugLog;

};

//update icon position

BIS_Thread_UpdateIconPosition = [] spawn {

while {!BIS_ShootingCompleted} do {

BIS_GTarget call BIS_targetIconUpdatePos;

sleep 0.01;

};

//["THREAD FINISHED","BIS_Thread_UpdateIconPosition"] call BIS_debugLog;

};

//is paused?

BIS_Thread_IsPaused = [] spawn {

while {!BIS_ShootingCompleted} do {

//paused: hide target and icon

waitUntil{BIS_ShootingPaused || BIS_ShootingCompleted};

if (BIS_ShootingCompleted) exitWith {};

["Shooting paused!"] call BIS_debugLog;

BIS_GTarget spawn BIS_targetIconHide;

BIS_GTarget animate ["terc",1];

BIS_GTarget allowDamage false;

//un-paused: show target and icon

waitUntil{!BIS_ShootingPaused || BIS_ShootingCompleted};

if (BIS_ShootingCompleted) exitWith {};

["Shooting un-paused!"] call BIS_debugLog;

BIS_GTarget spawn BIS_targetIconShow;

BIS_GTarget animate ["terc",0];

BIS_GTarget allowDamage true;

};

//["THREAD FINISHED","BIS_Thread_IsPaused"] call BIS_debugLog;

};

//turn target

BIS_Thread_TurnTarget = [] spawn {

while {!BIS_ShootingCompleted} do {

_dir = 180 + ([bIS_GTarget,player] call BIS_fnc_dirTo);

_pos = getPosASL BIS_GTarget;

BIS_GTarget setDir _dir;

BIS_GTarget setPosASL _pos;

sleep 1;

};

//["THREAD FINISHED","BIS_Thread_TurnTarget"] call BIS_debugLog;

};

while {!BIS_ShootingCompleted} do {

BIS_ShootingCompleted = false;

BIS_ShootingFailed = false;

//animate target

[bIS_GTarget,[_posStart,_posEnd],_speed,_speed,_hoverHeight] call BIS_animateObject;

//fsm for player states

_fsm = [bIS_GTarget,_end] execFSM "fsm\sniper_moving.fsm";

waitUntil{completedFSM _fsm};

//terminate the animation

terminate (BIS_GTarget getVariable "BIS_MainAnim_Spawn");

};

//remove handlers

BIS_GTarget removeAllEventHandlers "HandleDamage";

//safe-check the threads

_t = time;

waitUntil{(time > _t + 1) || (scriptDone BIS_Thread_UpdateIconText && scriptDone BIS_Thread_UpdateIconPosition && scriptDone BIS_Thread_IsPaused && scriptDone BIS_Thread_TurnTarget)};

if (time > _t + 1) then {

//terminate remaining running threads

if !(scriptDone BIS_Thread_UpdateIconText) then {

["THREAD 'BIS_Thread_UpdateIconText' TERMINATED!"] call BIS_debugLog;

terminate BIS_Thread_UpdateIconText;

};

if !(scriptDone BIS_Thread_UpdateIconPosition) then {

["THREAD 'BIS_Thread_UpdateIconPosition' TERMINATED!"] call BIS_debugLog;

terminate BIS_Thread_UpdateIconPosition;

};

if !(scriptDone BIS_Thread_IsPaused) then {

["THREAD 'BIS_Thread_IsPaused' TERMINATED!"] call BIS_debugLog;

terminate BIS_Thread_IsPaused;

};

if !(scriptDone BIS_Thread_TurnTarget) then {

["THREAD 'BIS_Thread_TurnTarget' TERMINATED!"] call BIS_debugLog;

terminate BIS_Thread_TurnTarget;

};

} else {

//["ALL THREADS FINISHED SUCCESSFULLY"] call BIS_debugLog;

};

sleep 1;

//hide icon

BIS_GTarget spawn BIS_targetIconHide;

//hide target

call BIS_sniperTargetDelete;

};

THere's probably a lot missing from these, interdependencies and whatever, but you can pop open the missions_e.pbo and see how they did it exactly.

Share this post


Link to post
Share on other sites

Does anyone understand this and got it to work? I don't understand it really. How is it being excuted? In menu action? I don't see where the call is?

Share this post


Link to post
Share on other sites

Its not execMovingtarget which actually moves the target ;)

The function you are looking for is found in: CA\missions_e\bootcamp\BootCamp_Shared\functions\functions_animations.sqf

Here is the one you want:

BIS_animateMoveSmooth =
{
private["_sleep","_object","_posStart","_posEnd","_deltax","_deltay","_deltaz","_distance","_tmax","_a","_vmax","_t","_ssaved","_animList","_animPhase","_progress","_posx","_posy","_posz","_anim","_taccel","_saccel","_sconst","_tconst"];
private["_wps","_positions","_distancesStart","_distancesPrev","_refWP","_ghostBall","_time","_hoverHeight","_dir"];

_sleep = 0.01;					//delay between each anim frame, lower values = smoother animation

_object = _this select 0;
_wps = _this select 1;			//array of all animation WPs

//hover height
if (count _this > 4) then {
	_hoverHeight = _this select 4;
};

//----------------------------------------------------------------------------------------------
//positioning & animating along waypoints ------------------------------------------------------

_positions = [];		//array of all WP positions
_distancesStart = [];	//array of WPs distances from the beginning of the animation
_distancesPrev = [];	//array of WPs distances from the previous WP
_refWP = _wps select 0;

private["_d","_dTotal","_tmpPos"];
_d = 0;
_dTotal = 0;

{
	//storing position of each WP
	//it's WP object
	if (typeName(_x) == "OBJECT") then {
		_tmpPos = getPosASL _x;
		if (_x == player) then {
			_tmpPos = [_tmpPos select 0, _tmpPos select 1, (_tmpPos select 2) + 0.8]; 
		};
	//it's position			
	} else {
		_tmpPos = _x;
	};
	_positions = _positions + [_tmpPos];


	//total from the start
	_d = _x distance _refWP;
	_dTotal = _dTotal + _d;
	_distancesStart = _distancesStart + [_dTotal];


	//from previous WP
	_distancesPrev = _distancesPrev + [_x distance _refWP];
	_refWP = _x;		

} forEach _wps;

//current WPs
_wpStart = 0;
_wpEnd = _wpStart + 1;

//count positions
_posStart = _positions select _wpStart;
_posEnd = _positions select _wpEnd;	

//count delta x,y,z
_deltax = (_posEnd select 0) - (_posStart select 0);
_deltay = (_posEnd select 1) - (_posStart select 1);
_deltaz = (_posEnd select 2) - (_posStart select 2);	

_dir =  [_posStart,_posEnd] call BIS_fnc_dirTo;
_object setDir (_dir-180);	

//display object at start position
if isNil("_hoverHeight") then {
	_object setPosASL (_positions select 0);
} else {
	_object setPos [(_positions select 0) select 0, (_positions select 0) select 1,_hoverHeight];
};
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------


//_vmax
if (count(_this) > 2) then {
	_vmax = _this select 2;
} else {
	_vmax = 15;
};

//_a
if (count(_this) > 3) then {
	_a = _this select 3;
} else {
	_a = 5;
};

//acceleration path
_taccel = _vmax/_a;
_saccel = 1/2 * _a * _taccel * _taccel;

//distance (of whole animation)
_distance = _distancesStart select (count(_distancesStart) - 1);
//["_distance",_distance] call BIS_debugLog;

//distance too short
if (2*_saccel > _distance) then {
	//["DISTANCE IS TOO SHORT"] call BIS_debugLog;
	//["_saccel (raw)",_saccel] call BIS_debugLog;
	//["_taccel (raw)",_taccel] call BIS_debugLog;		

	_saccel = _distance/2;
	_taccel = sqrt(_distance/_a);

	//["_saccel (fixed)",_saccel] call BIS_debugLog;
	//["_taccel (fixed)",_taccel] call BIS_debugLog;		

	//distance is too short -> object wont reach max speed
	_vmax = _a * _taccel;

	//there is no constant speed part in middle
	_sconst = 0;
	_tconst = 0;

//distance is fine
} else {
	//["DISTANCE IS FINE"] call BIS_debugLog;

	_sconst = _distance - 2*_saccel;
	_tconst = _sconst/_vmax;
};

//total time
_ttotal = 2*_taccel + _tconst;

_t = 0;
_tmax = _taccel;
_ssaved = 0;

_animList = [];
_animPhase = 0;
_animList = _animList + [{1/2 * _a * _t * _t}];
_animList = _animList + [{_vmax * _t}];
_animList = _animList + [{_vmax * _t - 1/2 * _a * _t * _t}];	

_time = time;

private["_sleepTime","_tover"];

_tover = 0;

while {_animPhase < count(_animList)} do {
	_t = _t + _sleep;

	_sleepTime = time;

	sleep _sleep;

	//real sleep time calculations
	_sleepTime = time - _sleepTime;
	_t = _t - _sleep + _sleepTime;
	if (_t > _tmax) then {
		_tover = _t - _tmax;
		_t = _tmax;
	};

	_anim = _animList select _animPhase;
	_s = call _anim;

	//------------------------------------------------------------------------------------------
	//positioning & animating along waypoints --------------------------------------------------
	_movedFromStart = _ssaved + _s;

	//searching for acctual _wpStart & _wpEnd
	while {_movedFromStart > _distancesStart select _wpEnd} do {
		_wpStart = _wpStart + 1;
		_wpEnd = _wpStart + 1;

		//["Current waypoints:",format["%1 -> %2",_wpStart,_wpEnd]] call BIS_debugLog;

		//count positions
		_posStart = _positions select _wpStart;
		_posEnd = _positions select _wpEnd;	

		//count delta x,y,z
		_deltax = (_posEnd select 0) - (_posStart select 0);
		_deltay = (_posEnd select 1) - (_posStart select 1);
		_deltaz = (_posEnd select 2) - (_posStart select 2);

		//set direction
		_dir =  [_posStart,_posEnd] call BIS_fnc_dirTo;
		_object setDir (_dir-180);			
	};

	//progress part -> object positioning
	_movedBetweenWPs = _movedFromStart - (_distancesStart select _wpStart);
	_progress = _movedBetweenWPs / (_distancesPrev select _wpEnd);
	if (_progress > 1) then {
		_progress = 1;
	};

	_posx = (_posStart select 0) + _deltax * _progress;
	_posy = (_posStart select 1) + _deltay * _progress;
	_posz = (_posStart select 2) + _deltaz * _progress;

	if isNil("_hoverHeight") then {
		_object setPosASL[_posx,_posy,_posz];
	} else {
		_object setPos[_posx,_posy,_hoverHeight];
	};


	//["_movedFromStart",_movedFromStart] call BIS_debugLog;
	//["_movedBetweenWPs",_movedBetweenWPs] call BIS_debugLog;
	//["_progress",_progress] call BIS_debugLog;
	//["_posx",_posx] call BIS_debugLog;

	//create a ghost-ball
	/*
	_ghostBall = "sign_sphere25cm_ep1" createVehicle [0,0,0];
	_ghostBall setObjectTexture [0,"#(argb,8,8,3)color(0.8,0.5,0.5,0.5,ca)"];
	_ghostBall setPosASL[_posx,_posy,_posz];
	*/


	//------------------------------------------------------------------------------------------


	if (_t == _tmax) then {
		_animPhase = _animPhase + 1;

		//[format["Animation ID%1 finished at distance %2 (took %3 secs)!",_animPhase-1,_ssaved + _s,_tmax]] call BIS_debugLog;

		//skip the middle part (animationPhase 1) if its time == 0
		if (_animPhase == 1 && _tconst == 0) then {
			_animPhase = _animPhase + 1;
			//["Animation ID1 skipped!"] call BIS_debugLog;
		};			

		if (_animPhase == 1) then {
			_tmax = _tconst;
		} else {
			_tmax = _taccel;
		};

		//_t = 0;
		_t = _tover;
		_ssaved = _ssaved + _s;
	};	
};

private["_pos"];

_pos = _positions select (count(_positions) - 1);

if isNil("_hoverHeight") then {
	_object setPosASL _pos;
} else {
	_object setPos [_pos select 0, _pos select 1, _hoverHeight];
};	
};

Now simply feed that with the target object and an array of waypoints (objects/positions), for example:

[target1, [wp1, wp2]] spawn BIS_animateMoveSmooth

Play around with the script to suit your needs (I personally call the function again at the end to loop it).

Hope I helped ;)

Andy455

Share this post


Link to post
Share on other sites

Andy,

Thanks a lot, I'm going to take another stab at it. I did open up the Mission_e file and it is in FMS. I will see what I can do, may I ask for some assistance?

Edited by Landdon

Share this post


Link to post
Share on other sites

Glad I helped Landdon ;) I'll see if I can make an example mission later.

Share this post


Link to post
Share on other sites

That would be most welcomed and needed! My goal is to make it Multi-player usable.

Share this post


Link to post
Share on other sites

Can anyone tell me how i get the Script postet by andy to work?? i try the Hole day....

Share this post


Link to post
Share on other sites
Can anyone tell me how i get the Script postet by andy to work?? i try the Hole day....

I have not tested....but do you have the Functions module placed on the map?

Share this post


Link to post
Share on other sites

Hmm Nope ....

My Knowlege about such scripts isnt very much ....

Can u explain the steps i have to go?

maby you can help me with a Sample Mission?

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  

×