N
Necromedes
Guest
I want to put a turret on my player object that will have a limited turning angle (can only turn 45 degrees in either direction.) That's not the issue, I can code that without any problems but what is the issue is the next bit of code I want to implement.
I need the turret to have a limited turning angle BUT I want it to match the angle of the player as well. So that when the player turns, the turret will be locked to the players angle and still have limited motion.
I put together some very basic code and it... kind of works. I'll post the code here:
As you can see, I tried to simply add the players image_angle to the existing limiting variables (simply 45, 45) and as I said above, it kind of works. The issue is that as the player turns, the angle limits of the turret don't seem to actually match up with the player. So the range of the mouses position either moves up or down depending on where the player is facing.
I hope this makes sense to people. I just don't know any other way to explain it but hopefully you can get the idea from the code snippet.
Any suggestions?
I need the turret to have a limited turning angle BUT I want it to match the angle of the player as well. So that when the player turns, the turret will be locked to the players angle and still have limited motion.
I put together some very basic code and it... kind of works. I'll post the code here:
x = obj_ship_overhead.x
y = obj_ship_overhead.y
image_angle = point_direction(x, y, mouse_x, mouse_y) + obj_ship_overhead.image_angle
if image_angle > limit_l + obj_ship_overhead.image_angle{
image_angle = limit_l + obj_ship_overhead.image_angle
}
if image_angle < limit_r + obj_ship_overhead.image_angle{
image_angle = limit_r + obj_ship_overhead.image_angle
}
y = obj_ship_overhead.y
image_angle = point_direction(x, y, mouse_x, mouse_y) + obj_ship_overhead.image_angle
if image_angle > limit_l + obj_ship_overhead.image_angle{
image_angle = limit_l + obj_ship_overhead.image_angle
}
if image_angle < limit_r + obj_ship_overhead.image_angle{
image_angle = limit_r + obj_ship_overhead.image_angle
}
As you can see, I tried to simply add the players image_angle to the existing limiting variables (simply 45, 45) and as I said above, it kind of works. The issue is that as the player turns, the angle limits of the turret don't seem to actually match up with the player. So the range of the mouses position either moves up or down depending on where the player is facing.
I hope this makes sense to people. I just don't know any other way to explain it but hopefully you can get the idea from the code snippet.
Any suggestions?