Lillani Lowell Posted March 11, 2015 Share Posted March 11, 2015 So, I am an advanced coder, but when it comes to physics and certain rotations; Second Life tends to have me perplexed (I'm not a math wizard, anyway).This is what I'm trying to do...I am working on a vehicle akin to to a hovercraft that when it moves forward, back, left, or right it needs to tilt/lean in the direction its moving (so, I'm using llLookAt) to create a dampened tilt in the direction it needs to move... this vehicle also tracks targets and needs to use llRotLookAt to rotate itself and orient the front of the vehicle toward a target.And here's the problem I am running into...llRotLookAt and llLookAt are not playing together nicely; whenever I used llLookAt it seems to orient the X axis of the vehicle with the X axis of the world; which is fine and dandy if the vehicle didn't need to physically turn.How do I make llLookAt maintain an upward Z axis while ignoring the forward X axis and letting llRotLookAt do its thing? Difficulty, no axis can be locked as it needs to be able to tilt on the X or Y axis freely while being able to rotate around the Z axis.Also to note, using the built in vehicle features is not an option; all the physic behaviours have to be custom coded. Link to comment Share on other sites More sharing options...
Lillani Lowell Posted March 11, 2015 Author Share Posted March 11, 2015 Or, alternatively... Is there a way I can use JUST llLookAt to clamp the Z axis up while making the X axis look in a specific direction? Link to comment Share on other sites More sharing options...
Dora Gustafson Posted March 11, 2015 Share Posted March 11, 2015 May I suggest: rotation Vec2RotHor( vector V ){ V = llVecNorm( V ); vector UP = < 0.0, 0.0, 1.0 >; vector LEFT = llVecNorm(UP%V); V = llVecNorm(LEFT%UP); // you want V confined to the horizontal plane return llAxes2Rot(V, LEFT, UP);} Where vector V is the direction you want the X-axis to pointThe function returns the requested rotation. Reference: llAxes2Rot, right and wrong in the wiki :smileysurprised::smileyvery-happy: Link to comment Share on other sites More sharing options...
Lillani Lowell Posted March 11, 2015 Author Share Posted March 11, 2015 Hey Dora, thanks for the response, but I don't understand what it's returning or how I would use its results, essentially. Let's say I want the Z axis of my object to point at <10, 0, 10> (relative of its position, leaning forward)... and I want the X axis of my object pointing to <20, 30, 15> (a random coordinate in the region). How am I using this function? And am I using it in llLookAt? llRotLookAt? Link to comment Share on other sites More sharing options...
Dora Gustafson Posted March 11, 2015 Share Posted March 11, 2015 I was focused on what you said about clamping the Z axis and assumed vertical up But you can clamp Z by setting UP in the function to what you want You need to normalize it with UP = llVecNorm( UP ); You may want to use Vec2RotTrue( vector V ) or Vec2RotHor( vector V ) in the reference The function is returning the rotation of your object, to rotate your object to the indicated rotation: llSetRot( Vec2RotTrue( V )); or similar for physical objects :smileysurprised::smileyvery-happy: Edit: to answer your last question: the function replaces llLookAt and the returned rotation should be used in llRotLookAt Deep note: All axes used in llAxes2Rot must be orthogonal and unit vectors This means that random z and x vectors will not satisfy the demands in general The given function recalculate either x or z direction to meet the demand Vec2RotTrue( vector V ) will calculate new z perpendicular to x and keep x Vec2RotHor( vector V ) will calculate new x perpendicular to z and keep z Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now