Legacy GM [SOLVED]image angle problem

A

Amazing creature

Guest
when holding the left mouse button, the player will do a blowing ability that aims towards the mouse, the problem is that before blowing in the direction it's supposed to, it appears to the right of the player


obj_player
create:
Code:
changedir = true
// blow ability
canblow = true // if able to use the blow ability
blow_start = 0 // 1. preparing blow ani, 2. blow ani and usage
enum states
{
   normal,
   blowing,
}
current_state = states.normal;
// the only thing that changes when changing the states are the player sprites

step:
Code:
/// blow
// if you can blow
if canblow = true
{
   if mouse_check_button(mb_left)
   {
      current_state = states.blowing
      // aim blow sprite
      changedir = false
      // face right
      if x < mouse_x
      {
         image_xscale = 1;
      }
      // face left
      if x > mouse_x
      {
         image_xscale = -1;
      }
     
      // preparing blow animation
      if blow_start = 0
      {
         sprite_index = spr_blowing0
         blow_start = 1
      }
     
      // blowing
      if blow_start = 2
      {
         sprite_index = spr_blowing1
               
         // the blow
         if !instance_exists(obj_blow)
         {
             instance_create(x,y,obj_blow) 
         }
      }
   }
}
   // release or not holding blow
   if mouse_check_button_released(mb_left)
   {
      current_state = states.normal
      blow_start = 0;
      changedir = true
   
      if instance_exists(obj_blow)
      {
         with(obj_blow) instance_destroy(); 
      }
   }
obj_blow
step:
Code:
// image direction
dir = point_direction(obj_player.x,obj_player.y,mouse_x,mouse_y)
image_angle = dir
// on player's position
if obj_player.x < mouse_x{
   
   x = obj_player.x//+15
   y = obj_player.y//+15
   } else {
   x = obj_player.x//-15
   y = obj_player.y//+15
   }
 

Attachments

obscene

Member
Not quite sure I understand, but possibly moving obj_blow's code to the End Step could solve this. Because it's created during the normal Step Event, it's own Step Event may not execute until the following frame, meaning that first frame draws when it's still in default position.
 

Slyddar

Member
It appears right as that’s the default position if no image_angle is given, and it exists for a step before running its own code. Pass the angle to the blow when it’s created.
Code:
var inst = instance_create(x, y, obj_blow);
inst.image_angle = point_direction(obj_player.x, obj_player.y, mouse_x, mouse_y);
 
A

Amazing creature

Guest
It appears right as that’s the default position if no image_angle is given, and it exists for a step before running its own code. Pass the angle to the blow when it’s created.
Code:
var inst = instance_create(x, y, obj_blow);
inst.image_angle = point_direction(obj_player.x, obj_player.y, mouse_x, mouse_y);
Hey it works, thanks!!!
 
Top