I'm trying to set up a CHOP for firing a gun that causes it to kick back according to its heading, but I'm having a really hard time conceptualizing the solution. Part of the issue is that I don't really understand matrices, quaternions, localtransform and effectivelocaltransform and such. Here's my current understanding of what I need to do:
Extract gun's current rotations
Calculate trajectory for recoil
Apply impulse
Step 1 is easy, and I've tried extracting the rotations with a cracktransform as well as converting those to a quaternion for a detail attribute. I'm just not sure what to do with that information. I can use a Pulse CHOP to perform the actual recoil, but how do I apply that recoil to the gun's current rotations instead of, for example, just the Z axis?
Not sure if I understand this correctly, but what prevents you from attaching a child object to the object that contains the world transforms and then applying the recoil to the child object's local transforms? That way, you don't have to grapple with the world transforms at all. If that can't be avoided, I would try and extract the world transforms as a matrix. If you invert this matrix and apply it, the object should snap back to the origin. Then you apply the recoil, and afterwards apply the world transform matrix (non-inverted) to get the object back to its original position. I'm not CHOPs literate enough to provide you with a step-by-step solution off the top of my head, but that's how I would try and tackle the problem.
I did work out a solution that seems to work so far, and that was to ignore world transforms entirely and apply the pulse to the local transforms. This even works inside of an APEX setup, although that's when it's by itself; I haven't tested how it performs when a character is holding it yet. I do, however, have a new problem now: I added a circle inside the gun's barrel to act as an emitter for a bullet and a muzzle flash, but I can't figure out how to reference geometry attributes inside a DOP network. I'm back to the problem I was having before, where if I apply velocity, it will apply it to the world axes rather than the circle's current rotations.
That turned out to be a relatively simple problem to solve: just add a point normal to the center point of the circle, and feed that into the velocity. Now on to adding the muzzle flash.