S
sTRACH
Guest
Hello,
I have a top-down character that consists of two objects - obj_head and obj_body.
obj_head is set to always face the mouse.
With obj_body, I want it to follow obj_head if obj_head's angle is greather or less than 45 degrees.
This code though there is a problem with it, worked the best so far:
image_angle == obj_body.image_angle
The outside if is supposed to check if the angle is > or < 45 degrees and it works fine.
When image_angle is 45(ish) and obj_head is at 359(ish) degrees, this code changes image_angle the opposite way. The same happens when image_angle is 315(ish) and obj_head.image_angle is 1(ish).
Can you please take a look at the code and help me out?
Thank you for your answers in advance.
I have a top-down character that consists of two objects - obj_head and obj_body.
obj_head is set to always face the mouse.
With obj_body, I want it to follow obj_head if obj_head's angle is greather or less than 45 degrees.
This code though there is a problem with it, worked the best so far:
Code:
if((360 - (image_angle - obj_head.image_angle)) % 360 > 45 and (360 - (image_angle - obj_head.image_angle)) % 360 < 315){
if(image_angle - obj_head.image_angle > 0){
image_angle = (ceil(obj_head.image_angle) + 45) % 360;
}
if(image_angle - obj_head.image_angle < 0){
image_angle = (ceil(obj_head.image_angle) - 45) % 360;
}
}
The outside if is supposed to check if the angle is > or < 45 degrees and it works fine.
When image_angle is 45(ish) and obj_head is at 359(ish) degrees, this code changes image_angle the opposite way. The same happens when image_angle is 315(ish) and obj_head.image_angle is 1(ish).
Can you please take a look at the code and help me out?
Thank you for your answers in advance.
Attachments
-
193.8 KB Views: 9