brinycann0nade
Member
I have sprites with four facing directions, up right down left. I want them to be set when an instance is moving in those directions. This kind of code has a problem:
if yprevious > y {objFace = facing.up};
if yprevious < y {objFace = facing.down;}
if xprevious> x {objFace = facing.left;}
if xprevious< x {objFace = facing.right;}
It sets the facing correctly most of the time but I think it only does left and right directions when it's not moving diagonally at all. Moving up and right registers the same as moving right and up. I've tried a lot of solutions but they all run into the same problem. Maybe I need to measure the the angle of the movement?
The way I want it to work: Imagine a square with an X in it. The object is moving in the top triangle, it faces up. If it's moving in the right triangle, it's facing right, etc.
Thanks for any help with this.
if yprevious > y {objFace = facing.up};
if yprevious < y {objFace = facing.down;}
if xprevious> x {objFace = facing.left;}
if xprevious< x {objFace = facing.right;}
It sets the facing correctly most of the time but I think it only does left and right directions when it's not moving diagonally at all. Moving up and right registers the same as moving right and up. I've tried a lot of solutions but they all run into the same problem. Maybe I need to measure the the angle of the movement?
The way I want it to work: Imagine a square with an X in it. The object is moving in the top triangle, it faces up. If it's moving in the right triangle, it's facing right, etc.
Thanks for any help with this.