DEFINE_GC_MOTION is the right UDF implementation for this. I see some variables are not defined in your UDFs. Are they defines somewhere else? Is there anything that is not working in this UDF? There is a video on using DEFINE_CG_MOTION with oversets:
https://www.youtube.com/watch?v=BO2e9_njh5g
Hope this helps.