Gun-recoil problem C#
Hey,
I have a script for a gun movement. While shooting, the gun is moving back and forth… that works fine! I also want the gun to rotate a little bit back and forth as part of the recoil. For some reason it is not rotating back to its original position. There is an inaccuracy about 0.007 every time I shoot. Does anyone see the problem with my script?
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
StartCoroutine (GunMovement());
}
}
IEnumerator GunMovement()
{
yield return new WaitForSeconds (0.025f);
for(var i=0;i<5;i++)
{
transform.Translate(new Vector3(0, 0, -0.04f));
transform.Rotate(new Vector3(-1, 0, -0.5f));
yield return new WaitForSeconds (0);
}
for(var i=0;i<5;i++)
{
transform.Translate(new Vector3(0, 0, 0.04f));
transform.Rotate(new Vector3(1, 0, 0.5f));
yield return new WaitForSeconds (0);
}
}
Thanks in advance!!
Comment
Your answer
Follow this Question
Related Questions
Check rotation of an obstacle 0 Answers
Undesired Angles with transform.Rotate(...) 0 Answers
Problems With .rotate behavior 1 Answer
Cant stop object/ridgidbody from rotating 2 Answers
Auto level an object 0 Answers