public var MoveAmount : float = 1;
public var MoveSpeed : float = 2;
public var GUN: GameObject;
public var MoveOnX : float;
public var MoveOnY: float;
public var DefaultPos : Vector3;
public var NewGunPos : Vector3;
function Start () {
DefaultPos = transform.localPosition;
}
function Update () {
MoveOnX = -Input.GetAxis( "Mouse X") * Time.deltaTime * MoveAmount;
MoveOnX = -Input.GetAxis( "Mouse Y") * Time.deltaTime * MoveAmount;
NewGunPos = new Vector3 ( DefaultPos.x+ MoveOnX, DefaultPos.y+ MoveOnY, DefaultPos.x) ;
GUN.transform.localPosition = Vector3.Lerp(GUN.transform.localPosition, NewGunPos , MoveSpeed+ Time.deltaTime);
}
I am trying to get the gun to follow the camera like CoD for example. But when i attach this to my gun it changes the position of it so I can only see the barrel.
First, don’t capitalize variable names (especially ALL CAPS which is only used on constants generally). Following the popular conventions means that Classes/Types and functions/methods should be capitalized.
if you want the gun position to be offset from where it is, just change it before setting the transform.position. Simply add it to x, or y, or z when you setup the vector.
Please also preview your posts and make sure the formatting is clean before posting (or edit the post afterward if you miss something). Remember, we are all just volunteer contributors here, so make it easy on your fellow developers when you are asking for free help, Do homework, research, try things, and post after you have gathered enough information to narrow down the possible replies you may get.