|
Annisetta Anadyr
Registered User
Join date: 16 Nov 2006
Posts: 20
|
11-22-2006 05:21
Thought I'd do some 'self-teaching' by trying to create a controllable flying object to sit on but I'm having real trouble with the control event. Pressing UP takes you up while the button is pressed and it sits hovering nicely. The problem though is that the game seems to have stored extra UP events and only submits them when another control key is pressed. So pressing DOWN takes you up for a few more events before the down events arrive to be processed. Added my control event below if it's any help. Any idea what I'm doing wrong here? control(key id, integer keyheld, integer change) { integer keypressed = keyheld & change; integer keydown = keyheld & ~change; integer keyreleased = ~keyheld & change; integer keyinactive = ~keyheld & ~change;
integer dirchange = FALSE;
if (keydown & CONTROL_UP ) { gCurrentLocation.z += 5; dirchange = TRUE; }
if (keydown & CONTROL_DOWN) { gCurrentLocation.z -= 5; dirchange = TRUE; }
if ( dirchange ) { llStopHover(); llApplyImpulse( gCurrentLocation, FALSE); }
vector pos = llGetPos(); // get our current location and set hover height above ground float BroomstickHeight = pos.z - llGround(ZERO_VECTOR); if (BroomstickHeight < gHoverHeight) { BroomstickHeight = gHoverHeight; } llSetHoverHeight(BroomstickHeight, TRUE, 1); if (BroomstickHeight > 50) { llSetBuoyancy(1.0); // can't hover properly above 50 without extra buoyancy } else { llSetBuoyancy(0.0); }
}
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
11-22-2006 05:29
looks as if your use of both held and ~change may be messing you up? You may find some useful info in this thread
|
|
Annisetta Anadyr
Registered User
Join date: 16 Nov 2006
Posts: 20
|
11-22-2006 05:53
From: Newgate Ludd looks as if your use of both held and ~change may be messing you up? You may find some useful info in this threadThe reason I started using ~change was because I was getting this behaviour. I started off with 'if (keyheld & CONTROL_UP)' and get exactly the same thing happen. I'll see if I can get anything else out of that thread you mentioned. Thanks for the reply 
|
|
Nynthan Folsom
Registered User
Join date: 29 Aug 2006
Posts: 70
|
12-01-2006 23:16
CONTROL_UP & keyheld will tell you if the up key is down CONTROL_UP & changed will tell you if the up key's state is different since the last event The correct logic to test for an up-key down event is as follows. if((CONTROL_UP & keyheld) && (CONTROL_UP & changed)) { // The key is down, but it was not before }To test for an up-key being held down: if((CONTROL_UP & keyheld) && !(CONTROL_UP & changed))) { // The key is being held down, and was down before }To test for an up-key up event: if(!(CONTROL_UP & keyheld) && (CONTROL_UP & changed) { // The key is not down, but it was before }
|