Jump to content

Two-part rotation in separate axes


Wulfie Reanimator
 Share

You are about to reply to a thread that has been inactive for 1842 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

43804b711b.png

So I have this little thing. It's a turret that rolls around its base to aim around itself, and pitches the cylindrical cannon to aim for targets at different altitudes.

This turret is linked to a larger linkset, so neither of them is the root (but the root's center will be the bottom of the base).

I'm having trouble with the math behind this, as usual. Rotating the base is pretty easy:

vector target_position; // Could be anything.

vector direction = llVecNorm(target_position - llGetPos());
direction.z = 0; // Ignore the Z offset, the base MUST stay upright.

rotation final = llRotBetween(<1,0,0>, direction);
llSetLinkPrimitiveParamsFast(2, [PRIM_ROTATION, final]);

Even going so far as rotating both, the base and the cannon to face the same direction is trivial, but I don't know how to add to the cannon's local Y rotation so that it would only pitch up/down without rolling around itself and looking all wonky.

  • Haha 1
Link to comment
Share on other sites

Wulfie --   That's hard to get your head around.  One of the best discussions I have seen is the one that Chalice Yao wrote ages ago and is now in the VirtualVerse site at https://www.virtualverse.one/forums/threads/kept-simple-rotate-object-towards-another-object.178/

Innula and I have each borrowed that bit of code and adapted it for controlling turrets and robot arms and whatever.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

13 hours ago, Rolig Loon said:

Wulfie --   That's hard to get your head around.  One of the best discussions I have seen is the one that Chalice Yao wrote ages ago and is now in the VirtualVerse site at https://www.virtualverse.one/forums/threads/kept-simple-rotate-object-towards-another-object.178/

Innula and I have each borrowed that bit of code and adapted it for controlling turrets and robot arms and whatever.

Helpful as ever, Rolig! Thank you for reminding me of that. I recall reading the old version of the thread before the forum migrated.

I was actually pretty close.. had the right idea anyway.. but couldn't get the calculation right for the other llRotBetween.
My final code looks something like this-ish:

vector target;

vector direction = llVecNorm(target - llGetPos());
direction.z = 0;

rotation final = llRotBetween(<1,0,0>, direction);

float distance = llVecDist(<target.x, target.y, 0>, <this.x, this.y, 0>);
rotation pitch = llRotBetween(<1,0,0>, llVecNorm(<distance, 0, pos.z - this.z>));

llSetLinkPrimitiveParamsFast(2, [PRIM_ROTATION, final,
    PRIM_LINK_TARGET, 3, PRIM_ROTATION, pitch * final]);

 

Edited by Wulfie Reanimator
typo
  • Like 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1842 days.

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
 Share

×
×
  • Create New...