Jump to content


Photo

Movement Error while idle in only one State


  • Please log in to reply
2 replies to this topic

#1 TonyLarison

TonyLarison

    GMC Member

  • GMC Member
  • 29 posts

Posted 28 March 2016 - 04:35 PM

I have an 8-Directional Game and I'm using a move script to call it up. Not only does it use 8 directions, but I've managed to get it to set idle and moving animations based on the enemy object's x & y to give it a facing movement. Now, I can get the moving portion to work flawlessly for all angles, but as for the idle animation, I can get all to set to the correct one except when the player object is >180, but <270 (so, Southwest to the enemy object), he tends to flip horizontally (as if there's an invisible image_xscale = 1).

 

I would say I need to address this, but the image_xscale works fine when he's facing Northwest/Northeast to the enemy object without it. 

 

 

///scr_move_1P
 
//Set the input
scr_get_input();
 
//Set the Depth
depth = -y
 
//Set Angle Variable
angle = point_direction(x,y,obj_player2.x,obj_player2.y)
 
//Get the axis
var xaxis = (right_key - left_key);
var yaxis = (down_key - up_key);
 
//Set Direction
var dir = point_direction(0, 0, xaxis, yaxis);
 
//Set Length
if (xaxis == 0 and yaxis == 0) {
    len = 0;
} else {
    len = Speed;
}
 
//Set xspeed & yspeed
xspeed = lengthdir_x(len, dir);
yspeed = lengthdir_y(len, dir);
 
//Move
x += xspeed;
y += yspeed;
 
//Control the Sprite Speed & Set Idle Animation
image_speed = 0.2
if (len == 0) image_index = 0
  
 
//Control Sprite Displayed during Move
if (len == Speed) and (angle <90)
    {sprite_index = spr_andrewalkback; image_xscale = -1;}
    else if (angle <180)
    {sprite_index = spr_andrewalkback; image_xscale = 1;}
    else if (angle <270)
    {sprite_index = spr_andrewalkfront; image_xscale = 1;}
    else if (angle <360)
    {sprite_index = spr_andrewalkfront; image_xscale = -1;}
   
 
  

Can anyone see anything I'm missing?

 

 


  • 0

#2 TonyLarison

TonyLarison

    GMC Member

  • GMC Member
  • 29 posts

Posted 28 March 2016 - 05:58 PM

Just an update:

 

I erased the image_xscale's all together and made actual left and right facing sprites. It still is doing it, but it doesn't make any sense.

 

Can someone see why the sprite would mirror image when (len == 0)??


  • 0

#3 TonyLarison

TonyLarison

    GMC Member

  • GMC Member
  • 29 posts

Posted 28 March 2016 - 10:45 PM

Anyone got any leads on what is wrong with the code above?
  • 0