User Tools

Site Tools


en:examples:objects:keep_object_facing_mouse

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:examples:objects:keep_object_facing_mouse [2018/09/14 05:38 (2 months ago)] (current)
sausage created
Line 1: Line 1:
 +====== Keep an Object facing the Mouse Position ======
 +Good for weapons that fire in the direction of the mouse
 +
 +===== Resource =====
 +
 +{{ :​examples:​arrow.png |}}
 +
 +===== Config =====
 +
 +<​code=ini>​
 +[Arrow]
 +Graphic ​        = @
 +Texture ​        = arrow.png
 +Pivot           = center
 +Position ​       = (0, 0, 0)
 +</​code>​
 +
 +===== Code =====
 +
 +<​code=c>​
 +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);
 +</​code>​
 +
 +
 +===== See also =====
 +[[en:​examples:​maths:​convert_vector_to_radian_angle|Convert a Vector to an Angle (radians)]]
  
en/examples/objects/keep_object_facing_mouse.txt ยท Last modified: 2018/09/14 05:38 (2 months ago) by sausage