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 ===== | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ===== Config ===== | ||
+ | |||
+ | < | ||
+ | [Arrow] | ||
+ | Graphic | ||
+ | Texture | ||
+ | Pivot = center | ||
+ | Position | ||
+ | </ | ||
+ | |||
+ | ===== Code ===== | ||
+ | |||
+ | < | ||
+ | orxVECTOR arrowPosition = orxVECTOR_0; | ||
+ | orxObject_GetPosition(arrow, | ||
+ | |||
+ | orxVECTOR mousePosition = orxVECTOR_0; | ||
+ | orxMouse_GetPosition(& | ||
+ | orxRender_GetWorldPosition(& | ||
+ | |||
+ | orxVECTOR direction = orxVECTOR_0; | ||
+ | orxVector_Add(& | ||
+ | |||
+ | orxFLOAT angle = orxMath_ATan(direction.fY, | ||
+ | |||
+ | orxObject_SetRotation(arrow, | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== See also ===== | ||
+ | [[en: | ||