A few overheads in setting up, but I now have a HUD that controls orientation and movement. I'm using the llDetectedUV function for both.

For the rotation this touch coordinate needs to be converted to an angle, which you can do using the llAtan2 function - just remember to subtract 0.5 from both x and y to move the origin to the centre.

*vector touchPoint = llDetectedTouchUV(0);*

*float angle = llAtan2(touchPoint.y - 0.5, touchPoint.x - 0.5);*

The angle will need adjusting so that clockwise is positive 0-180, and anticlockwise is negative. The OpenSim version that I'm using (0.7.02) returns inconsistent results for the four 90 degree quarters, so it might take some trial and error depending on what system you're using.

For movement, I'm just passing on the x component. Since this is just a number between 0 and 1 I'll use it to scale the movement. While on the subject, moving objects "forwards" is very easy using the built-in functions:

*// Get the current rotation*

*rotation myRot = llGetRot();*

*// Get the vector that is pointing "forwards"*

*vector fwd = llRot2Fwd(myRot);*

*// Get the current position*

*vector myPos = llGetPos();*

*// Move forward a distance based on variables maxSpeed and movementScale*

*myPos = myPos + (fwd * maxSpeed * movementScale);*

Just remember that an objects forward direction is along its positive x axis.

Time for lunch.

## No comments:

Post a Comment