- Home /
Aiming problem
Im trying to add aiming and Ive encountered a few problems
heres the code so far
void Aim()
{
if(Input.GetMouseButtonDown(1))
{
fpsCam.fieldOfView = 55f;
playerLook.mouseSensitivity = 50f;
rifle.position = rifleAimPos.position;
Debug.Log("Pistol is moving position");
pistolHolder.position = pistolAimPos.position;
Debug.Log("Pistol has moved");
}
else if(Input.GetMouseButtonUp(1))
{
fpsCam.fieldOfView = 70f;
playerLook.mouseSensitivity = 100f;
rifle.position = rifleStore.position;
pistolHolder.position = pistolHolderStore.position;
}
}
when i use this code, the rifle moves when you aim but the pistol never moves, it only changes the fov of the camera.
also, im trying to use lerp to smooth the transition but it wont work. it only moves on the z axis. ive made sure to set the pistol aim position to something else but it still wont move.
can anyone help me?
how do i lerp with positions
Answer by SpyderManToo · Feb 09, 2021 at 04:52 AM
ok idk how this worked but if i put the pistol instead of the pistolholder in the pistolholder slot, it worked, POG
Answer by GeroNL · Feb 09, 2021 at 02:56 AM
Make sure the behaviour to change the position is same with rifle. Try to change this :
pistolHolder.position = pistolAimPos.position;
to :
pistolHolder.position = rifleAimPos.position;
if it can, then your set of pistolAimPos.position doesn't work properly, try to look over there
For Lerp do it on set of "pistolAimPos.position", change the it with :
float SpeedMove = 2.5f;
position = Vector3.Lerp(position, finalPosition, SpeedMove * Time.deltaTime);
Hope it help.
the lerp code doesnt work bc it says cannot convert from unityengine.transform to unityengine.vector3
changing what the positino changes to still doesn't work. ;-;
Your answer
![](https://koobas.hobune.stream/wayback/20220613024819im_/https://answers.unity.com/themes/thub/images/avi.jpg)