I don't understand $cone_dot()

greatguys1

Epic Adventurer
MSC Developer
Warriors of the North
MSC Archivist
Joined
Apr 20, 2013
Messages
339
Reaction score
60
Age
26
Location
Yes
$cone_dot //(<point origin>,<cone origin>,<cone angles>) - Returns -1 to 1 indicating how far off the point is from straight forward in the view cone

I don't understand the explanation for what cone_dot does. From what I gather, it assumes the cone is a "view point", and returns -1 to 1 depending on how far off the point is from the center of the cone's view? I, however, don't understand what the numbers -1 to 1 indicates, as far as the point being off from the center.
 

Thothie

Administrator
Staff member
Administrator
Moderator
MSC Archivist
Joined
Apr 8, 2005
Messages
16,342
Reaction score
326
Location
lost
Don't think I've ever used $cone_dot (nor has it been used by anyone else, apparently) - only $within_cone, which returns a 0 or 1 depending on whether the target is inside the cone (even that seems to be a tad screwy). Both call the same function with a different return:
Code:
//$within_cone(<point origin>,<cone origin>,<cone angles>,<cone apex angle>)
//$within_cone2D(<point origin>,<cone origin>,<cone angles>,<cone apex angle>)
//- Returns 1 if <point origin> is within a cone. (2D ignores the z component.)
//- priority: very high, scope: shared
msstring CScript::ScriptGetter_Cone( msstring& FullName, msstring& ParserName, msstringlist& Params )
{
	//Whether a point is within a defined cone
	//Dot product from defined cone
	//priority: very high, scope: shared
	msstring Return;
	if( Params.size() >= 4 )	//point, cone origin, cone angles, cone fov
	{
		Vector PointOrigin = StringToVec( Params[0] );
		Vector ConeOrigin = StringToVec( Params[1] );
		Vector ConeAngles = StringToVec( Params[2] );
		float ConeFOV = cosf(atof( Params[3] ) / 2.0f);

		Vector vForward;
		EngineFunc::MakeVectors( ConeAngles, vForward, NULL, NULL );

		Vector	vec2LOS = PointOrigin - ConeOrigin;

		if( ParserName == "$within_cone2D" ||
			ParserName == "$cone_dot2D" ) { vec2LOS.z = 0; vForward.z = 0; }

		vec2LOS = vec2LOS.Normalize();
		float flDot = DotProduct( vec2LOS, vForward ); //#define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])

		if( ParserName.starts_with("$within_cone") ) 
		{
			if( flDot >= ConeFOV ) RETURN_TRUE
			else RETURN_FALSE
		}
		else RETURN_FLOAT( flDot ); //#define RETURN_FLOAT( a ) { sprintf( Return, "%.2f", a ); return Return; }
	}
	else return "0";
}
I suppose $cone_dot might get you the direction in which the target is from the cone's relative center, where as values less than the cosine of half the provided cone apex are outside the cone, maybe.

Generally, if I want the direction to a target I'm not using setmovedest to go to, I use $dir(<vec1>,<vec2>) and multiply it by velocity. eg. breathing fire sprites towards target:
Code:
{ breath_sprites_loop

	if FX_BREATH_ON
	callevent $randf(0.1,0.3) breath_sprites_loop
	//shoot sprites from middle head to breath target via $dir
	local L_BREATH_POS $getcl(FX_OWNER,origin)
	local L_OWNER_YAW $getcl(FX_OWNER,angles)
	local L_OWNER_YAW $vec.yaw(L_OWNER_YAW)
	vectoradd L_BREATH_POS $relpos($vec(0,L_OWNER_YAW,0),$vec(0,FX_BREATH_RANGE,0)) //FX_BREATH_RANGE = dist to target

	local L_START $getcl(FX_OWNER,attachment1)
	local L_END L_BREATH_POS

	local L_BREATH_DIR $dir(L_START,L_END)

	setvard FX_BREATH_SPR_VEL L_BREATH_DIR
	vectormultiply FX_BREATH_SPR_VEL $randf(200,300)
	cleffect tempent sprite explode1.spr L_START setup_breath_sprite update_breath_sprite
}

{ setup_breath_sprite
[...]
	cleffect tempent set_current_prop velocity FX_BREATH_SPR_VEL
}
 
Top