Question by
The-Evster · Apr 15, 2017 at 06:43 PM ·
camerafpscamera-movementshootingrecoil
Camera Recoil Script Not working Correctly
I have tried to make a camera recoil function but it doesn't work. Here is my code
void RecoilFunction()
{
//Reset rotation
if (recoilX > 0)
{
recoilX = Mathf.Lerp(recoilX, 0, Time.deltaTime);
}
if (recoilY > 0)
{
recoilY = Mathf.Lerp(recoilY, 0, Time.deltaTime);
}
//Lerp Between Recoil rotation and default rotation
gameCamera.transform.localRotation = Quaternion.Euler(gameCamera.transform.localRotation.x + recoilX, gameCamera.transform.localRotation.y + recoilY, 0);
}
Increasing the recoilX and recoilY variables happens in anther function
if (!isLocalPlayer)
{
return;
}
RaycastHit hit;
float rayDistance = 600;
Ray ray = gameCamera.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0));
if (currentMag > 0)
{
//Setting Recoil
recoilX = 0.5f;
recoilY = 0.5f;
//Call OnShoot Method on the server
CmdOnShoot();
if (Physics.Raycast(ray, out hit, rayDistance))
{
currentMag -= 1;
if (hit.collider.tag == PLAYER_TAG)
{
CmdPlayerShot(hit.collider.name, damage);
}
}
}
I'm not sure why this isn't working and I hope you can help me out. Thank you in advance.
Comment
Your answer
Follow this Question
Related Questions
Simple Recoil and Reset System 0 Answers
C# Camera based Recoil 0 Answers
Recoil system 0 Answers
Trying to turn the Tank Game Camera script into perspective projection. 1 Answer
Camera Lock on GUI 0 Answers