rotation

Creating scripts
Post Reply
User avatar
Kirk Keller
Posts: 3
Joined: Thu Aug 28, 2014 2:30 am
Has thanked: 1 time
Been thanked: 3 times

rotation

Post by Kirk Keller »

Hi all.

I'm building a board game that features game pieces that move via a dialog menu.

The game pieces are not children of the board.

The game pieces, when they're placed are oriented correctly on the board (facing 'forward').

The dialog menu provide them the option to move forward, back, left back/forward, right back/forward (it's a hex board).

Here's the question: I'd like to have the piece rotate 180 degrees to the original placed position if the player moves back, 0 degrees to the original if they move forward, etc.

Thus far, however, I've frankly been stumped on the rot commands available. I imagine this is a relatively simple line of script but I'm stumped.

Anyone with a suggestion?

(p.s, I'd be happy to invite folks when I get the first prototype out of the door if anyone is interested)
These users thanked the author Kirk Keller for the post:
Carlos Loff
User avatar
Min Tigerpaw
Posts: 223
Joined: Sun Mar 24, 2013 3:52 pm
Has thanked: 332 times
Been thanked: 160 times

Re: rotation

Post by Min Tigerpaw »

Hi Kirk – rotations in lslScript are a bit tricky:
The reason for this is, that rotations are dealt with by rotarions which are pretty abstract beasts as we all are used to the more perceiveable representations in the euler-coordinates with degree of rotation around the x,y and z-axis. I usually keep track of the current rotation of moving parts in euler-coordinates and then convert to rotations.
For your problem you need to get the the local rotation rotPiece of your game-piece and multiply with the intended rotation rotChange.
As the piece is not linked to the game in your approach you also will need a script in the piece directing its movements with llSetRot(rotPiece).

initial rotation of piece (script in piece):
rotPiece = llGetLocalRot();
after rotation:
rotPiece = rotPiece * rotChange;

where rotChange is derived by:
vecChange = <dx,dy,dz>; // e.g. for a rotation of 90° around z-axis <0.0,0.0,90.0>
vecChange *= DEG_TO_RAD;
rotChange = (rotation)llEuler2Rot(vecChange);


hope that helps - if not you can IM me and we can script a 2-piece model for demo. ;)

Cheers
Min
These users thanked the author Min Tigerpaw for the post:
Kirk Keller
User avatar
Kirk Keller
Posts: 3
Joined: Thu Aug 28, 2014 2:30 am
Has thanked: 1 time
Been thanked: 3 times

Re: rotation

Post by Kirk Keller »

Worked like a charm.

I was almost there, but didn't realize that there is a rotation type in addition to vectors. So I was getting errors because of the misassignment of types (I was declaring everything as a vector).

Now I just need to get clear on my rotations for the moves but the script works perfectly.

Thanks.
These users thanked the author Kirk Keller for the post:
Min Tigerpaw
Post Reply