A
Aaron Walton
Guest
I'm trying to keep my oGun positioned at the same place on oPlayer, depending on what angle the player is at. It's a side-on game, but with a zero gravity element that means the player can walk on walls or the ceiling, so oPlayer isn't always at image_angle == 0. I have something that basically works, but only allows for four angles:
Now, I honestly can't think of a time that the player won't be at one of these angles, but when I accidentally placed my sprite at a slightly diagonal angle and my gun suddenly stopped following him, I figured I ought to fix this just in case. I'm guessing that the lengthdir function will be the answer, but I haven't gotten it to work. Here's what I tried:
But for some reason, when I use this instead of the other code, oGun's location is moved to the top left corner (I'm assuming 0,0, but haven't checked that for sure) of the room. Did I make some obvious mistake with how I coded this? Could it be interacting with some code elsewhere in the game perhaps?
GML:
with(oPlayer)
{
if image_angle == 0
{
other.x = x;
other.y = y + 7;
}
if image_angle == 180
{
other.x = x;
other.y = y - 7;
}
if image_angle == 270
{
other.x = x - 7;
other.y = y;
}
if image_angle == 90
{
other.x = x + 7;
other.y = y;
}
}
GML:
with(oPlayer)
{
other.x = lengthdir_x(0,image_angle);
other.y = lengthdir_y(7,image_angle);
}