Jump to content
Sign in to follow this  
granQ

Always going left..

Recommended Posts

Ok.. i will try to explain it.

What i want is to move the player 1 meter to his left, no matter what direction he is watching.

Esp if I can do this with vector, velocity would be awesome.

The true purpose is to use the math for a missile guidance system but got problem with the moving to left. (or right).

So anyone that can give me any pointers?

Share this post


Link to post
Share on other sites

ah, I think I get what you mean. That way I can find the "left" position of the missile and setpos it.. not as cool as using setvelocity but i guess it works :)

Will try it later :)

Share this post


Link to post
Share on other sites

Oki.. i did a script, tried to use your suggestion with "modelToWorld". However i keep getting errors like: generic error #sleep 2;

So could anyone see something wrong with this?

/*
Steer missile script made by granQ.
Made for SFP, Swedish Forces Pack.
Feel free to use, adjust for own purposes.
Script can for instance be started with an fired eventhandler.
*/

_vehicle = _this select 0;
_weapon = _this select 1;
_ammo = _this select 4;
sleep 0.1;

_missile = NearestObject [_vehicle, _ammo];

player sidechat format ["Defined: %1 as _missile", _missile];

if ("ARRAY" == typename _missile) then
{
_missile = _missile select 0;
};
if ("OBJECT" == typename _missile) then
{
while {alive _missile} do
{
	_dirArray = _vehicle weaponDirection _weapon;
	_dirElev = asin(_dirArray select 2 ) - asin( vectorDir vehicle player select 2);

	_dirDegrees = (_dirArray select 0) atan2 (_dirArray select 1);
	_dirToMissile = ((getpos _missile select 0) - (getpos _vehicle select 0)) atan2 ((getpos _missile select 1) - (getpos _vehicle select 1));
	_dirDegrees = _dirDegrees + 360;
	_dirToMissile = _dirToMissile + 360;

	if (_dirToMissile < _dirDegrees) then 
	{
			_WorldPos= _missile modelToWorld [0.2,0,0];
		_missile setpos _WorldPos;
	};
	if (_dirToMissile > _dirDegrees) then 
	{
			_WorldPos= _missile modelToWorld [-0.2,0,0];
		_missile setpos _WorldPos;
	};


	_height = (getposASL _missile select 2) - (getposASL _vehicle select 2);
	_distance = _vehicle distance _missile;
	_degreeToMissile = asin (_height/_distance);

	if (_dirElev > _degreeToMissile) then
	{
			_WorldPos= _missile modelToWorld [0,0,0.2];
		_missile setpos _WorldPos;
	};
	if (_dirElev < _degreeToMissile ) then
	{
			_WorldPos= _missile modelToWorld [0,0,-0.2];
		_missile setpos _WorldPos;
	};
};
};

Share this post


Link to post
Share on other sites
Oki.. i did a script, tried to use your suggestion with "modelToWorld". However i keep getting errors like: generic error #sleep 2;

From the biki: sleep must be called inside of a context which is interruptible, i.e. a script executed by execVM or spawn.

Share this post


Link to post
Share on other sites

yeah shouldn't be that.. it starts with a fire eventhandler.. and when removed "sleep" i still get error but for something else.

I feel like the game knows its wrong but not what.. which puts me in the same position.

EDIT. Haha, seems you were right actually.. i asked my beta tester what his init was EXACTLY.. he had exec instead of execVM.

Case closed. (somewhat.. the behavior still bad of the missile but..)

Edited by granQ

Share this post


Link to post
Share on other sites

Just a tip...

_missile = NearestObject [_vehicle, _ammo]; in a parallel scripts will cause you headaches once the mission gets under load. It will fail to catch the missile since it may not be executed while the missile is near enough.

Since the actual eventhandler code is a call, it is better to expand the _this parameter so that the generated object is sent as a 6th (_this select 5) element in the array.

Something like:

this addEventHandler ["fired",{_this [color="Red"][b]+ [nearestObject [_this select 0,_this select 4][/b][/color]] execVM "scripts\EH-FiredGrad.sqf"}];

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  

×