The issue is with my physical weapon feature. This feature uses a coroutine to begin shooting out raycasts at a certain point in the animation and then stop at a certain point in order to allow a raycast arc to be made that follows the weapon visually. I have raycasts being shot out every frame. After each raycast, it uses a vector3 lerp and the current running time of the attack animation to move the raycast over a certain amount. It does this until it hits the end vector3 offset point and attack end time to create a nice arc that follows the weapon animation.
The issue is the lerp calculator seems to be pumping out different vector3 positions based on if I'm inside a location or outside. I can't see any code that should be affected by this.
Heres the basic ray calculation code:
Code: Select all
//gets forward facing vector using player camera.
attackcast = GameManager.Instance.MainCamera.transform.forward;
//sets a Quaternion angle for adjusting arccast by calculating the angle of my forward look.
objectRotation = Quaternion.LookRotation(attackcast);
//lerps through lerp cordinates to make arc cast. Locks y position to main camera z rotation(look up/down angle/radian).
attackcast = Vector3.Lerp(new Vector3(110f, GameManager.Instance.MainCamera.transform.rotation.z, GameManager.Instance.MainCamera.transform.position.z), new Vector3(-90f, GameManager.Instance.MainCamera.transform.rotation.z, GameManager.Instance.MainCamera.transform.position.z), percentagetime);
//rotate the attack cast based on players current forward camera position. Ensure raycasts always rotate properly with player
attackcast = (objectRotation * attackcast);
//Grab the players position for start of ray plus any offset vectors passed through (I'm not using any offsetting in my code)
Vector3 startPosition = GameManager.Instance.MainCamera.transform.position + offset;
//shoot the ray from players camera to the end vector distance and position
Ray ray = new Ray(startPosition, attackcast);
Here is the gimmick I used to get around it for now and it produces almost the same arc inside or out, but as you can tell, it requires insanely high vector3 differences to produce the same raycast arc by the end of the attack/lerp calculation.
Code: Select all
if(GameManager.Instance.IsPlayerInside)
attackcast = Vector3.Lerp(new Vector3(-90f, GameManager.Instance.MainCamera.transform.rotation.z, GameManager.Instance.MainCamera.transform.position.z), new Vector3(110f, GameManager.Instance.MainCamera.transform.rotation.z, GameManager.Instance.MainCamera.transform.position.z), percentagetime);
else
attackcast = Vector3.Lerp(new Vector3(-720f, GameManager.Instance.MainCamera.transform.rotation.z, GameManager.Instance.MainCamera.transform.position.z), new Vector3(720f, GameManager.Instance.MainCamera.transform.rotation.z, GameManager.Instance.MainCamera.transform.position.z), percentagetime);