Jump to content
Sign in to follow this  
Nightgirl Destiny

Help with llTakeControl

Recommended Posts

I'm trying to make a wheelchair. It will attach to the wearer, and contains a pose that seats the user correctly. What I would also like to do is have the wheels rotate correctly as it moves. I'm using an animated texture to mimic movement rather than rotating the actual prims. So far, I can get them to rotate forwards and backwards when the user presses his up and down arrow keys, and rotate in opposite directions to turn the chair when the left or right arrow keys are pressed. However, I would also like to programme slightly different behaviour when both the up arrow and one of the left or right arrows are pressed together, and it's this I am struggling with.

Here's an extract from the script I've got so far:

    control(key id, integer level, integer edge)
    {
        if (level & CONTROL_FWD)
        {
            if (edge & CONTROL_FWD)
            {
                llSetLinkTextureAnim(2, ANIM_ON | SMOOTH | ROTATE | LOOP, ALL_SIDES, 1,1,0, TWO_PI, -TWO_PI);
                llSetLinkTextureAnim(3, ANIM_ON | SMOOTH | ROTATE | LOOP, ALL_SIDES, 1,1,0, TWO_PI, TWO_PI);
                llSetLinkTextureAnim(4, ANIM_ON | SMOOTH | ROTATE | LOOP, ALL_SIDES, 1,1,0, TWO_PI, TWO_PI);
                llSetLinkTextureAnim(5, ANIM_ON | SMOOTH | ROTATE | LOOP, ALL_SIDES, 1,1,0, TWO_PI, -TWO_PI);
            }
            else
            {
                llSetLinkTextureAnim(2, ANIM_ON | SMOOTH | ROTATE | LOOP, ALL_SIDES, 1,1,0, TWO_PI, -TWO_PI);
                llSetLinkTextureAnim(3, ANIM_ON | SMOOTH | ROTATE | LOOP, ALL_SIDES, 1,1,0, TWO_PI, TWO_PI);
                llSetLinkTextureAnim(4, ANIM_ON | SMOOTH | ROTATE | LOOP, ALL_SIDES, 1,1,0, TWO_PI, TWO_PI);
                llSetLinkTextureAnim(5, ANIM_ON | SMOOTH | ROTATE | LOOP, ALL_SIDES, 1,1,0, TWO_PI, -TWO_PI);
            }
        }
        else
        {
            if (edge & CONTROL_FWD)
            {
                llSetLinkTextureAnim(LINK_SET, FALSE, ALL_SIDES, 0, 0, 0.0, 0.0, 1.0);
            }
        }

This works correctly. The texture starts to rotate when the Up arrow is pressed, and stops when it's released. How would I modify it (to start with) to do exactly the same when (say) the Up and Left arrows were held down at the same time.

Thanks in advance for any help you can offer.

Share this post


Link to post
Share on other sites

Just add in the additional key's bitflag to your conditional statement with another bitwise & operator:

if(edge & CONTROL_FWD & CONTROL_ROT_LEFT)

 

Here's a link to a good tutorial on how to use the operators:

http://lslwiki.digiworldz.com/lslwiki/wakka.php?wakka=bitwise

(i'm trying to find a good explanation of edge and level- will update when I find it or make one myself) They're all a mess, here's my best shot:

 

Level and Edge correspond to a control's particular input signal as it is polled by the computer.

level denotes where the button is: 1 when pressed ,  0 when unpressed
edge denotes when it moves: 1 when changing, 0 when stable

It is often times useful to test the following four conditions instead of just the pressed or unpressed state of a button. For example: if you only want to generate one event per press even when a button is held, you'd want to use the start condition. If only the level value is checked, it will generate events constantly when held down.

 

Point A: integer untouched = ~(level | edge); // both level and edge are false
Point B: integer held = level & ~edge; // level is true and edge is false
Point C: integer start = level & edge; // both level and edge are true
Point D: integer end = ~level & edge; // level is false and edge is true

Signal Diagram:
    _____    _____
____|   |____|   |___
  ^   ^      ^   ^
  A   B      C   D

EDIT: added edge and level potion.

Edited by Myrmidon Hasp
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...