• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

(Solved) An objects x and y, follow a specific point on another rotating object

darijs1

Member
Im trying to have a head object follow a body object, but the body objects original sprite x and y is in its center.
how can i make the head object be higher on the body object (like where the head and neck should be) instead of being in the center of the body.
What is the simple way of doing this?

(the only thing ive tried is adding -78 to the y position of the head, which makes the head not be in the right place at all (except if the body is completely still at an angle of 0))
 

Simon Gust

Member
You can use lengthdir_ functions for that
Code:
/// obj_head step event
x = obj_body.x + lengthdir_x(78, obj_body.direction);
y = obj_body.y + lengthdir_y(78, obj_body.direction);
Now, this may not work like expected. I depends on the body's direction where the head will be.
Clear is, that the head is attached in a circular way around the body with a radius of 78 in this example.
If direction is 90, the head will be exactly 78 pixels above the body's origin.
If direction is 0, the head will be exactly 78 pixels to the right of the body's origin.
and so on.
 
D

Dandysius

Guest
If I understand correctly you problem, I think you need to move the origin in head sprite
 

darijs1

Member
You can use lengthdir_ functions for that
Code:
/// obj_head step event
x = obj_body.x + lengthdir_x(78, obj_body.direction);
y = obj_body.y + lengthdir_y(78, obj_body.direction);
Now, this may not work like expected. I depends on the body's direction where the head will be.
Clear is, that the head is attached in a circular way around the body with a radius of 78 in this example.
If direction is 90, the head will be exactly 78 pixels above the body's origin.
If direction is 0, the head will be exactly 78 pixels to the right of the body's origin.
and so on.
Thank you very much for this. With a few adjustments (im using the physics engine), this worked perfectly.
 
Top