How movement works

From Second Life Wiki
Revision as of 06:27, 2 June 2007 by Jocelyn Linden (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The server is authoritative about agent position. The client is authoritative about camera position and rotation.

The viewer sends an upstream packet up to 20 times per second with information about movement keys (forward, backward, up, down). The message is named "AgentUpdate" and contains a U32 "ControlFlags". The control flag constants are in llagentconstants.h.

The agent is physically simulated on the simulator as a vertically stretched sphere. It is moved by application of impulses. In order to impart velocity with brief keypresses the viewer first sends a "nudge", then the normal key press. See AGENT_CONTROL_NUDGE_AT_POS.

The agent can be moved with the arrow keys or with ASWD when the chat bar is closed. The viewer maintains its own view of which keys are down during any particular frame. This is maintained in LLKeyboard (llkeyboard.cpp).

Every frame, LLKeyboard::scanKeyboard() is called, resulting in calls to functions like agent_push_forward() in llviewerkeyboard.cpp. The key to function mapping is provided in the file app_settings/keys.ini. These functions set variables in LLAgent indicating what keys have been pushed that frame by calling functions like LLAgent::moveAt() or LLAgent::moveYaw(). This sets an internal mControlFlags mask.

Once per frame, send_agent_update() in llviewermessage.cpp is called. This constructs the complete set of control flags for the agent and, if different, transmits the new set to the server. The server then handles computation of current position and transmits the position back through the ObjectUpdate pathway used for all object position transmission.

Note that agent positions are velocity and acceleration interpolated, so if there is a delay in network transmission the agent may appear to move through a wall or floor. The client does not perform collision detection.

See also Category:LSL Movement for LSL calls related to movement.