User Tools

Site Tools


en:examples:objects:keep_object_facing_mouse

Keep an Object facing the Mouse Position

Good for weapons that fire in the direction of the mouse

Resource

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/objects/keep_object_facing_mouse.txt · Last modified: 2020/08/19 19:44 (4 years ago) by sausage