====== Keep an Object facing the Mouse Position ====== Good for weapons that fire in the direction of the mouse ===== Resource ===== {{ examples:objects:arrow.png |}} ===== Config ===== [Arrow] Graphic = @ Texture = arrow.png Pivot = center Position = (0, 0, 0) ===== Code ===== orxVECTOR arrowPosition = orxVECTOR_0; orxObject_GetPosition(arrow, &arrowPosition); orxVECTOR mousePosition = orxVECTOR_0; orxMouse_GetPosition(&mousePosition); orxRender_GetWorldPosition(&mousePosition, orxNULL, &mousePosition); orxVECTOR direction = orxVECTOR_0; orxVector_Add(&direction, &arrowPosition, &mousePosition); orxFLOAT angle = orxMath_ATan(direction.fY, direction.fX); orxObject_SetRotation(arrow, angle); ===== See also ===== [[en:examples:maths:convert_vector_to_radian_angle|Convert a Vector to an Angle (radians)]]