Jump to content
anfo

Object movement

Recommended Posts

Hi

 

I'm wondering if anybody knows of a command or script that smoothly moves objects similar to this:

 

 

Thanks

Share this post


Link to post
Share on other sites
44 minutes ago, anfo said:

knows of a command

setPos.

45 minutes ago, anfo said:

smoothly moves objects

EachFrame eventhandler.

Share this post


Link to post
Share on other sites

By linearConversion of x,y and z

Spoiler



TAG_fnc_moveObject = {
	_object = param[ 0, objNull, [ objNull ] ];
	
	if ( isNull _object ) exitWith {
		"Invalid Object supplied" call BIS_fnc_error;
	};
	
	_this select [ 1, count _this ] params [
		[ "_to", [0,0,0], [ [] ], [ 3 ] ],
		[ "_duration", 10 ],
		[ "_from", getPosATL _object, [ [] ], [ 3 ] ]
	];
	
	if ( _to isEqualTo [0,0,0] ) exitWith {
		"Invalid TO position given" call BIS_fnc_error;
	};
	
	_from params[ "_fromX", "_fromY", "_fromZ" ];
	_to params[ "_toX", "_toY", "_toZ" ];
	
	_startTime = time;
	_endTime = time + _duration;
	
	while { time < _endTime } do {
		_x = linearConversion[ _startTime, _endTime, time, _fromX, _toX ];
		_y = linearConversion[ _startTime, _endTime, time, _fromY, _toY ];
		_z = linearConversion[ _startTime, _endTime, time, _fromZ, _toZ ];
		
		_object setPosATL [ _x, _y, _z ];
	};
	
	_object setPosATL _to;
};

[ box, screenToWorld[ 0.5, 0.5 ], 10 ] spawn TAG_fnc_moveObject;

 

 

By vector math

Spoiler



TAG_fnc_moveObject = {
	_object = param[ 0, objNull, [ objNull ] ];
	
	if ( isNull _object ) exitWith {
		"Invalid Object supplied" call BIS_fnc_error;
	};
	
	_this select [ 1, count _this ] params [
		[ "_to", [0,0,0], [ [] ], [ 3 ] ],
		[ "_duration", 10, [ 0 ] ],
		[ "_from", getPosATL _object, [ [] ], [ 3 ] ]
	];
	
	if ( _to isEqualTo [0,0,0] ) exitWith {
		"Invalid TO position given" call BIS_fnc_error;
	};
	
	_diff = _to vectorDiff _from;
	_distPerSecond = ( vectorMagnitude _diff ) / _duration;
	_dir = vectorNormalized _diff;
	
	_startTime = time;
	_endTime = time + _duration;
	
	while { time < _endTime } do {
		_pos = _from vectorAdd ( _dir vectorMultiply ( _distPerSecond * ( time - _startTime )));
		
		_object setPosATL _pos;
	};
	
	_object setPosATL _to;
};

[ box, screenToWorld[ 0.5, 0.5 ], 10 ] spawn TAG_fnc_moveObject;

 

 

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

×