// Basado en el script de la demo de disparos de technotdc.

#pragma strict

var amountXY : Vector2 = new Vector2(1, 1);
var maxAmount : Vector2 = new Vector2(2, 2);
var minAmount : Vector2 = new Vector2(-2, -2);
var smooth : float = 6;

private var OriginalPosition : Vector3;

private var XComp : float;
private var YComp : float;
private var Final : Vector3;
 
function Start (){
    OriginalPosition = transform.localPosition;
}
 
function ReasignOriginalValues(NewGunPos : Vector3){
	OriginalPosition = NewGunPos;
	transform.localPosition = NewGunPos;
}

function ReasignOriginalRotValues(NewGunRot : Quaternion){
	transform.localRotation = NewGunRot;
}


function Update (){
 
	if(FPCStatus.IsFire2Down){
		transform.localPosition = OriginalPosition;
		return;
	}
	
	if(FPCStatus.IsAiming){
		return;
	}
	
		
	if(FPCStatus.IsAxisXActive || FPCStatus.IsAxisYActive){
		if(FPCStatus.IsAxisXActive){
			XComp = -FPCStatus.AxisXValue * amountXY.x;
			XComp = Mathf.Clamp (XComp, minAmount.x, maxAmount.x);
		}
		else
			XComp = 0;
		
		if(FPCStatus.IsAxisYActive){
			YComp = -FPCStatus.AxisYValue * amountXY.y;
			YComp = Mathf.Clamp (YComp, minAmount.y, maxAmount.y);
		}
		else
			YComp = 0;
			
		Final = new Vector3(OriginalPosition.x+XComp, OriginalPosition.y+YComp, OriginalPosition.z);
		transform.localPosition = Vector3.Lerp(transform.localPosition, Final, Time.deltaTime * smooth);     
	}
	
	//  El retorno a la posicion inicial se realiza por defecto en el HeadbobberGun, que lleva todo el peso del dibujado.
	// no así la rotación que sla ralizará rotationGun cuando no se esté moviendo el raton.
}