Alternative Shoulder Calculation

If you are having trouble getting your head around the Quaternion calculation then you can alternatively use the Vector3 cross product:

Vector3 shoulderOffset = Vector3.Cross(Vector3.up, shootDir) * shoulderOffsetAmount;

Realising that Cross Product gives you a Vector perpendicular to the two input Vectors might make it easier to “visualise” what is actually happening.

4 Likes

Thanks for this. This helped me understand what we were doing.

I was also curious if there were alternate calculations using some method on Transform. It turns on there ALMOST is. You can do the following, which converts the local position of (0.5, 1.7, -1) on the shooterUnit to a world position.

The reason I say ALMOST is because the BaseAction_OnAnyActionStarted event is fired before the unit has a chance to rotate towards its target. This results in an incorrect position for the first shot after a MoveAction() but it is a correct position if the unit fires a 2nd (or 3rd or…) shot because it is aligned in the correct direction.

shooterUnit.transform.TransformPoint(0.5f, 1.7f, -1f); 
//converts a local position relative to the shooterUnit's transform to a world Vector3.

Unfortunately this trick didn’t work this time, but it could be useful in the future. I bet there’s a way to make the cinemachine camera track against that local transform offset (i.e. the transform would move in world space, but stay at a constant local position). It’s late and I didn’t try to figure it out.

Privacy & Terms