Talan Mackenzie
The Rocketeer
Join date: 15 Aug 2004
Posts: 14
|
11-16-2004 05:08
For several reasons, the most prominent being llSetLocalRotation, I need to be able to generate the rotation required to turn object at point A toward point B. Essentially, I need to generate the rotation required to use llSetRot as though it was (a much faster) llLookAt. I've built two model cones which -should- be looking at the toucher when touched, but neither are working. One attempts to tackle the problem using llRotBetween (to find the difference between the current rotation and the final rotation, then rotate)... default { state_entry() { //placeholder for now }
touch_start(integer total_number) { vector TOUCHERPOS = llDetectedPos(0); vector MYPOS = llGetPos(); rotation MYROT = llGetRot(); vector ROTFWD = llRot2Fwd(MYROT); vector AHEAD = MYPOS + ROTFWD; rotation LOOKHEREROT = llRotBetween(AHEAD, TOUCHERPOS); llSetRot(MYROT - LOOKHEREROT); } } The other attempts to mash vector data regarding its own position and the targets into a rotation, by finding the vector between them, normalizing, mashing into degrees, then degrees to radians, then radians to rotations via llEuler2Rot, like so... default { state_entry() { //placeholder }
touch_start(integer total_number) { vector MYPOS = llGetPos(); vector TOUCHERPOS = llDetectedPos(0); vector LAMDA = TOUCHERPOS - MYPOS; vector NORM = llVecNorm(LAMDA); vector DEGREE = NORM * 360; vector RADIAN = DEGREE * DEG_TO_RAD; rotation ROT = llEuler2Rot(RADIAN); llSetRot(ROT); } } Apperantly I've managed to screw both these methods up, so if you have a fix for either, or you have a whole new way to make llSetLocalRot point at given vectors, please speak up!
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-16-2004 06:33
The second approuch is just *wrong* it can't work. first off you *can't* add or subtract rotation and get a sain answer. Only multiply or devide. I can't count the number of times I've said this on the forums and in chat. try default { state_entry() { //placeholder for now }
touch_start(integer total_number) { vector TOUCHERPOS = llDetectedPos(0) - llGetPos(); vector AHEAD = <0,0,1>; rotation LOOKHEREROT = llRotBetween(AHEAD, TOUCHERPOS); llSetRot(LOOKHEREROT); } }
futs with the ahead to get the object pointed in the right direction. not 100% sure this will work, haven't tested it.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Talan Mackenzie
The Rocketeer
Join date: 15 Aug 2004
Posts: 14
|
Success
11-16-2004 06:38
Looks like I was making llRotBetween way more complicated than it was. Thanks for the code sample, works perfectly.
|