(solved) Angle between two objects
by jeremy young · in iTorque 2D · 05/28/2011 (7:42 am) · 3 replies
I'm fairly new to torque and I love it. I need to find the angle between two objects and was wondering if there is an easy way to figure it out or should I just figure the diference between the x and y coordinates and do some right triangle trig math. Any help would be awesome. I have been reading, coding, and reading code but I can't seem to find out.
About the author
Trained in Automation, Programming, and electronics, but thanks to this wonderful economy is now a Pipefitter.
#2
Thanks for the quick response, I was able to get it working from the direction you pointed me in. this is what I ended up with.
[code]%vector = t2dVectorSub(%playerposition, %mousePosition);
%angle = mRadToDeg(mAtan(%vector.y, %vector.x)) + 90;
%sidea = getWord(%vector, 1);
%sideb = getWord(%vector, 0);
%power = mSqrt((%sidea * %sidea) + (%sideb * %sideb));
%power *=15;
player.setImpulseForcePolar(%angle, %power, false);[code]
05/30/2011 (4:14 pm)
Thanks for the quick response, I was able to get it working from the direction you pointed me in. this is what I ended up with.
[code]%vector = t2dVectorSub(%playerposition, %mousePosition);
%angle = mRadToDeg(mAtan(%vector.y, %vector.x)) + 90;
%sidea = getWord(%vector, 1);
%sideb = getWord(%vector, 0);
%power = mSqrt((%sidea * %sidea) + (%sideb * %sideb));
%power *=15;
player.setImpulseForcePolar(%angle, %power, false);[code]
#3
05/31/2011 (4:22 am)
Glad you got it working. :)
Torque Owner Alain Labrie
Ware-Wolf Games
Either way you have to use trig to figure this out.
This might help
Math theory and Torque script math functions