User Tools

Site Tools


en:examples:objects:keep_object_facing_mouse
no way to compare when less than two revisions

Differences

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


Next revision
en:examples:objects:keep_object_facing_mouse [2018/09/13 22:38 (6 years ago)] – created sausage
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: 2020/08/19 19:44 (4 years ago) by sausage