I'm trying to write a piece of code that swings an object forward and backwards. Eventually it will be for swinging a close combat weapon in an FPS.
IEnumerator swing() {
Vector3 orgPosition = holdRight.transform.localPosition;
holdRight.transform.localPosition = Vector3.Slerp(orgPosition, this.camera.transform.forward * 2.0f, 1.0f * Time.deltaTime);
yield return new WaitForSeconds(0.5f);
holdRight.transform.localPosition = Vector3.Slerp(holdRight.transform.localPosition, orgPosition, 1.0f * Time.deltaTime);
attacking = false;
}
Now what I'm trying to do here is slerp the weapon (child of camera) forward relative to the camera. Wait half a second and then slerp it back to the original position.
The forward slerping is not relative to the camera. In the original orientation that I start with, it slerps forward. If I turn the character around 180 degrees, it's slerping backwards.
Also it doesn't slerp back to the original position after .5 seconds. It just stays where it is.
Could anyone point out where I'm wrong and/or provide better guidelines to swing a close combat weapon around using code. (I have 0 experience using animators ;))
↧