Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotation with llTakeControls

Solomon Devoix
Used Register
Join date: 22 Aug 2006
Posts: 496
06-21-2007 18:27
If an avatar is sitting on a prim, the arrow keys cause the camera view to rotate around the seated avatar. What I would like to do instead is cause the left arrow key to cause the prim on which the avatar is seated to rotate 45 degrees around its local Z axis. I thought I understood how that should work, but when I use the script below, the camera view still rotates and the prim never moves. What am I doing wrong?

CODE

key Avatar;

rotation angleChange;

default{

state_entry()
{
llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION);
angleChange = llEuler2Rot( <0, 0, 45> * DEG_TO_RAD );
}


changed( integer change )
{
if( change & CHANGED_LINK )
{
Avatar = llAvatarOnSitTarget();

if( Avatar != NULL_KEY )
{
llRequestPermissions( Avatar, PERMISSION_TAKE_CONTROLS );
}
else
{
if (llGetPermissions() & PERMISSION_TAKE_CONTROLS) llReleaseControls();

}
}
}

run_time_permissions(integer perms)
{
integer desired_controls =
CONTROL_LEFT |
CONTROL_RIGHT |
CONTROL_ROT_LEFT |
CONTROL_ROT_RIGHT;

if (perms & PERMISSION_TAKE_CONTROLS)
{
llTakeControls(desired_controls, TRUE, TRUE);
}
}

control(key id, integer down, integer new)
{
integer pressed = down & new;
integer held = down & !new;
integer released = !down & new;

if ( (pressed & CONTROL_LEFT) ||
(pressed & CONTROL_ROT_LEFT) ||
(held & CONTROL_LEFT) ||
(held & CONTROL_ROT_LEFT) )
{
llSetRot(angleChange * llGetRot());
}
}
}
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
06-21-2007 19:03
From: Solomon Devoix
CODE

control(key id, integer down, integer new)
{
integer pressed = down & new;
integer held = down & ~new;
integer released = ~down & new;

if ( (pressed & CONTROL_LEFT) ||
(pressed & CONTROL_ROT_LEFT) ||
(held & CONTROL_LEFT) ||
(held & CONTROL_ROT_LEFT) )
{
llSetRot(angleChange * llGetRot());
}
}
}

You wrote "new(pressed)" OR "~new(held)" for the trigger to take action. It must be repugnant.
_____________________
:) Seagel Neville :)
Solomon Devoix
Used Register
Join date: 22 Aug 2006
Posts: 496
06-21-2007 19:20
From: Seagel Neville
You wrote "new(pressed)" OR "~new(held)" for the trigger to take action. It must be repugnant.

[grumbles]

Yes, hit one key too far over to the left, apparently. However, the same problem remains even with that typo corrected.
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
06-21-2007 19:37
llTakeControls(desired_controls, TRUE, TRUE); means that all controls are worked normally. And the camera moving is one of them. I can't tell which is given priority over. You put CONTROL_LEFT down, too. So what about having users press and hold Shift key when they use it?
_____________________
:) Seagel Neville :)
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-21-2007 19:43
From: Seagel Neville
You wrote "new(pressed)" OR "~new(held)" for the trigger to take action. It must be repugnant.
Well, it's certainly verbose, but technically not redundant, I think, because there should be a distinct event for the leading edge (new) of the "down" key press, followed by a stream of events (~new) while the key stays down. So the logic seems to be a long way of saying "if (down)".

You'll note that with the script as posted, CONTROL_LEFT (Shift-LeftArrow) works fine, but CONTROL_ALT_LEFT (LeftArrow) spins the cam instead of the prim. If you can get by with handling all events in the script and not passing any for normal avatar control, calling
llTakeControls(desired_controls, TRUE, FALSE);
(instead of ...TRUE, TRUE) will make it work for the ROT controls too. (I do not know why it doesn't spin both the prim and the cam, with "TRUE, TRUE".)
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
06-21-2007 19:59
From: Qie Niangao
Well, it's certainly verbose, but technically not redundant, I think, because there should be a distinct event for the leading edge (new) of the "down" key press, followed by a stream of events (~new) while the key stays down. So the logic seems to be a long way of saying "if (down)".
I got it. Thanks.
From: Qie Niangao
llTakeControls(desired_controls, TRUE, FALSE);
(instead of ...TRUE, TRUE) will make it work for the ROT controls too.
Really? I didn't know that. You mean it works just rotation, but not posisiton?
_____________________
:) Seagel Neville :)
Solomon Devoix
Used Register
Join date: 22 Aug 2006
Posts: 496
06-21-2007 20:02
You're right; the second TRUE should be a false. I could have SWORN that I'd tried changing that, and it still didn't work properly, but I guess not...

Thanks.