OpenMetaverse.AgentManager.AgentMovement.TurnToward C# (CSharp) Method

TurnToward() public method

Rotates the avatar body and camera toward a target position. This will also anchor the camera position on the avatar
public TurnToward ( System.Vector3 target ) : bool
target System.Vector3 Region coordinates to turn toward
return bool
            public bool TurnToward(Vector3 target)
            {
                if (Client.Settings.SEND_AGENT_UPDATES)
                {
                    Quaternion parentRot = Quaternion.Identity;

                    if (Client.Self.SittingOn > 0)
                    {
                        if (!Client.Network.CurrentSim.ObjectsPrimitives.ContainsKey(Client.Self.SittingOn))
                        {
                            Logger.Log("Attempted TurnToward but parent prim is not in dictionary", Helpers.LogLevel.Warning, Client);
                            return false;
                        }
                        else parentRot = Client.Network.CurrentSim.ObjectsPrimitives[Client.Self.SittingOn].Rotation;
                    }

                    Quaternion between = Vector3.RotationBetween(Vector3.UnitX, Vector3.Normalize(target - Client.Self.SimPosition));
                    Quaternion rot = between * (Quaternion.Identity / parentRot);

                    BodyRotation = rot;
                    HeadRotation = rot;
                    Camera.LookAt(Client.Self.SimPosition, target);

                    SendUpdate();

                    return true;
                }
                else
                {
                    Logger.Log("Attempted TurnToward but agent updates are disabled", Helpers.LogLevel.Warning, Client);
                    return false;
                }
            }