|
JoeTheCatboy Freelunch
Registered User
Join date: 14 Jun 2006
Posts: 42
|
01-27-2007 21:05
Hey all, I'm working on a sentry gun that tracks avatars, and I'm having problems with it... flopping around. I want to know the formula to make it so that it doesn't "roll around" pardon the pun.
If you're confused, think of this. A box that points its forward axis at a target. Of course, the way it does it is the quickest, and the turret ends up on its side sometimes (still pointing at the target of course.) Here's what I'm using to rotate it.
llSetLocalRot(getRotToPointAxisAt(AXIS_FWD, target));
and here's the global function
rotation getRotToPointAxisAt(vector axis, vector target) { return llGetRot() * llRotBetween(axis * llGetRot(), target - llGetPos());
Basically, I just want to do STATUS_ROTATE_Y (or X), FALSE, haha
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
01-27-2007 21:44
well, there are those quaternion jocks who are going to tell you this is obvious. While we wait for one of them to post, here's what I *think*.
After the rotation you do now, your up axis isn't up any more. You need one more rotation to make it be up. Maybe something using llRot2Up(), Fwd(), and Left(), then compute a new up, and put them all back into a rot.
Good luck.
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
01-28-2007 04:57
Lee is basically correct. llRotBetween, returns a rotation which has an axis perpendicular to the plane formed by the 2 vectors passed to it. So if that plane isn't horizontal, i.e. if your turret and target aren't at the same height, the axis won't be vertical, and it will rotate your turret off-kilter. Quats confuse the bajeezus out of me, so best to assemble one from axes. Start with the obvious one, the axis pointing at your target, and Normalize it: vector X_axis = llVecNorm( target - llGetPos() ); Now you want a left axis which is always horizontal, so take the cross product of true vertical and your X_axis: vector Y_axis = <0,0,1> % X_axis; This won't work in only 2 cases, when the target is exactly above or below your turret, either of which cause the 2 vectors to be colinear, the cross product of which is ZERO_VECTOR. You can include a conditional check for those cases, or just place limits on your turret preventing it from reaching true vertical. Unless this is a freely hovering turret, there'd realistically be limits on it's degree of rotation anyway. The up axis is now just the cross product of the other two, which you can feed directly into llAxes2Rot: rotation DesiredRotation = llAxes2Rot( X_axis, Y_axis, X_axis % Y_axis );
|
|
Adare McCallen
Registered User
Join date: 16 Nov 2007
Posts: 0
|
12-23-2007 06:40
I'm trying to write a script that does that same as the one above using the samne function etc. I have a free floating turret that tracks an avatar but sometimes end up "up side down". How do you work out which way is up to rotate it back round? I don't understand the answer given here though 
|