Topspin: Applying torque in relation to an aim vector

I’ve got my player kicking a football (soccer) in a direction determined by a Vector3. That works fine. Now I’m looking to add a variable amount of top/backspin (and eventually sidespin) based upon the players inputs.

I know I should be using rigidbody.AddTorque() and can get a global torque applied just fine but I want it applied in relation to the direction of the kick Vector3. My current searches have got me looking at Quaternions but the reference material is a little dry and I can’t wrap my head around them just yet.

So, how do I determine the required AddTorque(x, y, z) values to get topspin, given a movement direction described by my Vector3?

I hope that makes sense and appreciate any help in the right direction.

Well, what are the chances, I’ve figured it out myself. I’ll share the explanation here in case anyone else stumbles across this in the future…

Firstly, I discovered that AddTorque can accept a Vector3 as the parameter and it’ll use the direction of that for the spin axis and the magnitude (how long it is) as the amount of force applied.

So, I can take my kick direction rotate it 90 degrees so it’s perpendicular to the direction the ball is being kicked and then use that like so…

// make a copy of kickdir vector and remove the y component
var topspin = kickdir;
topspin.y = 0;
    
// rotate that by 90 degrees so it's like the axle of a wheel for my ball
topspin = Quaternion.Euler(0, 90, 0) * topspin;
    
// use that with AddTorque and set the magnitude to 150
rigidbody.AddTorque(topspin.normalized * 150);

Kinda straightforward in the end but I hope that helps someone else in the future.