I was able to do this easily when modifying the other axis to create a left to right and right to left arc. But the moment I try to move it along the top down axis to create a downward arc, I start getting really funky results as the player rotates their camera more and more. My dumb math head can't figure this out, and I can't find a solution on google. Any assist would help.
Here is the code:
This sets up the attack cast to be rotated over the time of the attack to create a swing arc. It creates a vector3 forward value using the player camera and then passes that to a function that rotates it based on the vector3 rotate values put in.
Code: Select all
Vector3 attackcast = AmbidexterityManager.mainCamera.transform.forward;
if (weaponState == WeaponStates.StrikeRight)
attackcast = ArcCastCalculator(new Vector3(0, -90, 0), new Vector3(0, 90, 0), percentagetime * arcSpeed, attackcast);
else if (weaponState == WeaponStates.StrikeDownRight)
attackcast = ArcCastCalculator(new Vector3(35, -35, 0), new Vector3(-30, 35, 0), percentagetime * arcSpeed, attackcast);
else if (weaponState == WeaponStates.StrikeLeft)
attackcast = ArcCastCalculator(new Vector3(0, 90, 0), new Vector3(0, -90, 0), percentagetime * arcSpeed, attackcast);
else if (weaponState == WeaponStates.StrikeDownLeft)
attackcast = ArcCastCalculator(new Vector3(35, 35, 0), new Vector3(0, -30, -35), percentagetime * arcSpeed, attackcast);
//THIS IS THE SWING WITH THE ERROR TO BE SPECIFIC: ALL OTHER SWINGS THAT USE ONLY THE Y VALUE WORK FINE\\
else if (weaponState == WeaponStates.StrikeDown)
attackcast = ArcCastCalculator(new Vector3(45, 0, 0), new Vector3(-45, 0, 0), percentagetime * arcSpeed, attackcast);
else if (weaponState == WeaponStates.StrikeUp)
Code: Select all
//uses vector3 axis rotations to figure out starting and ending point of arc, then uses lerp to calculate where the ray is in the arc, and then returns the calculations.
public Vector3 ArcCastCalculator(Vector3 startPosition, Vector3 endPosition, float percentageTime, Vector3 castDirection)
{
if (flip)
{
startPosition = startPosition * -1;
endPosition = endPosition * -1;
}
//sets up starting and ending quaternion angles for the vector3 offset/raycast.
Quaternion startq = Quaternion.Euler(startPosition);
Quaternion endq = Quaternion.Euler(endPosition);
//computes rotation for each raycast using a lerp. The time percentage is modified above using the animation time.
Quaternion slerpq = Quaternion.Lerp(startq, endq, percentageTime);
Vector3 attackcast = slerpq * castDirection;
return attackcast;
}