turn the character according to the position of the mouse

A

AlexisSablay0

Guest
Hello i'm making a shooter and i have a animation when he shoot but he get activated only if i click with the left button of the mouse.
if the character is moving to the left i use :
if mouse_check_button(mb_left) and keyboard_check(ord("D"))
{
sprite_index = sRunSleft;
}

The fact is than if the mouse is in the right and the character moving to the left the animation will be in the left and not in the right so i want create an animation for when he is moving left and shooting right but i don't know how can i activate him so please can somebody help me :)
 
You need something like this but there was an issue in this type of code where you needed to use " || " somewhere between 0 and 360 degree difference.
Code:
var _dir = point_dir(x, y, mouse_x, mouse_y);

if (_dir > 0 && _dir < 90)
 {
  sprite_index = sRunSrightUP;
 }
if (_dir > 90 && _dir < 180)
 {
  sprite_index = sRunSleftUP;
 }
if (_dir > 180 && _dir < 270)
 {
  sprite_index = sRunSleftDOWN;
 }
if (_dir > 270 && _dir < 360)
 {
  sprite_index = sRunSrightDOWN;
 }
 
You are welcome :) There might be little issue like you aren't checking the solid directions ( 0° 90° 180° 270° 360°) but between them.

And there is another version of this code;
Code:
var _dir = point_dir(x, y, mouse_x, mouse_y);

if (_dir > 45 && _dir < 135)
 {
  sprite_index = sRunSup;
 }
if (_dir > 135 && _dir < 225)
 {
  sprite_index = sRunSleft;
 }
if (_dir > 225 && _dir < 315)
 {
  sprite_index = sRunSdown;
 }
if (_dir > 315 || _dir < 45)
 {
  sprite_index = sRunSright
 }
 
Top