Legacy GM [solved]problem attaching sprite to rotating player

woods

Member
i know this is an elementary problem, but i just cant seem to get it.

i have my obj_player which when he takes damage i want to add a wind spiral sprite to his airplane.
the issue i am facing is i cant seem to get the spiral to "stick to" the rear of the player sprite as the player rotates.
player sprite needs to stay centered if that makes a difference.

here is the code for player movement involving rotating..

Code:
/// movement

direction = image_angle;

if keyboard_check(ord("W"))
{
image_angle -= 5;
}
if keyboard_check(ord("S"))
{
image_angle += 5;
}


// collide with ground and change direction

if place_meeting(x,y+32,obj_ground) and image_angle <= 90
{
image_angle = 10;
}
if place_meeting(x,y+32,obj_ground) and image_angle > 90
{
image_angle = 170;
}

//flip sprite if upsidedown

if (image_angle < 270 and image_angle > 90)
{
image_yscale = -1;
}
else
{
image_yscale = 1;
}


// adjust image_angle out of scope

if (image_angle < -90)
{
image_angle = 270;
}
if image_angle > 350
{
image_angle = -10;
}
 
G

Gillen82

Guest
Have a look at lengthdir_x() and lengthdir_y() functions. This might help you out
 

woods

Member
ive taken a few looks at lengthdir..... for some reason im not seeing how it works to get my rotation in order.. maybe im just thick ;o) i donno...

but i did manage to get things figured out without it tho.

obj_spiral step event
Code:
/// follow damaged player

x = obj_player.x;
y = obj_player.y;

direction = obj_player.direction;
image_angle = obj_player.image_angle;
image_xscale = -obj_player.image_xscale;
 
Lengthdir_x / y will give a fixed point around an object. Your airplane x / y is the origin point, and it needs values for length and angle. Length would be the distance between the planes x / y and how far from it you want the wind spiral to be placed. The angle would be the planes image_angle + 180, as the wind spiral is at the back of the plane.

So, whichever angle the plane is facing, the wind spiral is always at the back of it and at the same distance.

If you want to know what it's really doing - look up some trigonometry examples. In some you will see them showing how a triangle with a 90 degree corner can be used to find a point on a circle. The trigonometry functions that do this are used in the lengthdir_x / y function.
trig.png
 

woods

Member
thanks dude for the explanation... ill have to chew on that for a while but i can see where it makes a lil sense


but i did solve the issue without it already rocketboy.. so yea i got it sorted out ;o)
 
Top