So I'm assuming the problem is the fact that it's a childed object, but please correct me if I'm wrong. Here's my code:
if(gun[curWeapon] != null)
{
//float x = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localEulerAngles.x, 180f + (rotation.x - Camera.main.transform.eulerAngles.x), 0.8f) - 180f;
float y = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localEulerAngles.y, 180f + (rotation.y - transform.localEulerAngles.y), 0.6f);
float z = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localEulerAngles.z, 180f - ((rotation.y - transform.localEulerAngles.y)/2f), 0.6f);
gun[curWeapon].gunObject.transform.localEulerAngles = new Vector3(0f, y, z);
float a = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localPosition.x, 0f + (position.x - transform.localPosition.x), 0.1f);
float c = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localPosition.z, 1f + (position.z - transform.localPosition.z), 0.1f);
gun[curWeapon].gunObject.transform.localPosition = new Vector3(a, 0f, c);
}
position = transform.localPosition;
rotation = new Vector3(Camera.main.transform.eulerAngles.x, transform.localEulerAngles.y, 0f);
I've made sure that `gun[curWeapon].gunObject` is not being affected by any other part of the script, it just jumps back and forth.
The script is an experimental gun sway and movement script.
Thanks in advance! ;)
↧