Want to add a script or a project? Upload it and a half million people will see it and your name here this year.
|Useful Subroutines||Here is a little snippet for the rotationally-challenged, or those who have some complex solution but want something much simpler. // How to rotate an object so it points its X axis (which is the 'forward' axis on prims) towards another object? // One complex solution is to take the object's rotation, take the other object's position, try to calculate the angle/rotation in between, adding it to the current rotation... // // Way too complex. It's much simpler to calculate the total rotation that needs to be set in one swoop.|
|Useful Subroutines||Awesome, isn't it? That one line does all the magic. The logic here is that the llRotBetween returns the rotation between the norm'd vector <1,0,0>, which would be the forward vector of an object without any rotation applied (remember, X axis = forward in prims), and the normal vector that points from your object to the target. And that's the whole rotation that needs to be set. // // // Code: // // B // * // | Z height // | // A XYdistance | // *--------------------------- X axis (<1,0,0>) // // // Now, this is already dead seksi, but it can have an effect that some people want to avoid: the object that does the pointing will rotate around its own length. I.e. it will roll left/right along its body axis. How to avoid that? // // Solution: Do two different rotations. one that does the left/right turning, followed by a rotation that simply tilts the object up/down. Think of a classic concept like a gun turret. The turret barrel never rotates around the axis it points at, it just moves up/down and left/right. // // Hokay, let's do the up/down first. The easiest way to get that rotation is to act like both object positions have the same Y value, and just are their combined XY distance apart on the X axis. Think two-dimensional.|
|Useful Subroutines||And then we get back to the little first line of code in this post, modified:|
|Useful Subroutines||Ta-dah. This will return the rotation that will make our object point upward correctly at the other object. Not left/right, just the correct upwards angle. the 'vTarget.z - vPos.z' gets done to get the height difference between the two objects. // // Now how to do left/right? Easy, it uses the same idea as the above concept of getting the needed up/down rotation, except this time we disregard the Z coordinate and just use the XY difference. // // Like this: // Code: // // Y // ^ // | // | *B // | // | // | *A // | // ------------------> X (<1,0,0>) // // This time we don't even need to take care of any distance considerations. What we want, we'll get with:|
|Useful Subroutines||There we go. The needed left/right rotation. Now, let's combine and get the result! // // We take the up/down rotation, and multiply the left/right roation to it..which is the way of combining rotations...and it basically goes in reverse order. Think of the left/right applied first before the up/down gets done to the result rotation. Basically read from right to left when mupltiplying rotations. // // And there we go. Correct rotation towards a target without rotating around the own axis. Hope this was educational!|
Back to the Best Free Tools in Second Life and OpenSim.