GML Connecting Sprite to Moving Characters

D

Drysteven

Guest
I am trying to connect a helmet on top of my player. This way I can change out the helmets for the player and not have to make a walking animation for each type of helmet. The problem I have is when the character moves the helmet slides to the side. I would just make it move both objects at the same time except I am using a motion planning grid and it seems excessive to make the helmet use the grid and pathfinding as well. Thanks!
 

roozilla

Member
Not sure I understand the unintended behavior of your helmet but why don't you just make a draw event that draws your character and then the helmet on top? What size are your sprites and where are the draw starting coordinates? You'll have to consider this and the offset that occurs with different size sprites. Someone may have a better suggestion since I'm not an expert with animations and sprites but that is how ive gotten around the issue.
 
D

Drysteven

Guest
So when the character moves to the left for example the character will be slightly ahead of the helmet and it's like the helmet is attached to the head by a string. I want to know how to make it stick to the top of the characters head right now I am just placing the two objects on top of each other and then using the mp grid with the character then setting the x of the helmet to the x of the character and same for the y. They both are 32 by 32 and the helmet has a lot of blank space so both sprites have the same origin and I don't need to offset the helmet.
 

pipebkOT

Member
I'm not an expert too but you could try connecting the helmet object IN the player step event? Not in the helmet step event

Code:
Helmet.x=x
Helmet.y=y-8
So they move at the same time

You will have to adjust the number to fit the helmet in the head and not in the center of the player aprite, like the other user said . You need to calculate it

This way the helmet will be always with the player
Replace helmet with your helmet object name
 
D

Drysteven

Guest
I think what I need to do is create velocity for the character and offset the helmet by the velocity using the direction so basically the length_dir function. This isn't ideal and it seems like it should be easier to do this, but it will work. I see what you're saying with setting the x's to be equal and same as the y's but offsetting so that it is on the head but the origin is the same on both so they are already in the right positions. It's just when the character moves that it disconnects from the character. Sorry, I'm, not the best at explaining this. Thanks!
 

pipebkOT

Member
Like I said put the code in the player step event. So is the player who is carrying the helmet. Not the helmet who is catching the player.


So make sure to not put the code in the helmet step event. Instead put it in the player
 
D

Drysteven

Guest
Right yeah, I did that but it still seems to stay behind.
 
D

Drysteven

Guest
In the player step event:
Code:
if (moving) {
    helmet.x = x + lengthdir_x(spd, direction);
    helmet.y = y + lengthdir_y(spd, direction);
}
else {
    helmet.x = x;
    helmet.y = y;
}
I tried this and it works except when the player stops moving, starts moving, or changing direction. It only doesn't work for 1 frame then it catches up.
 
D

Drysteven

Guest
Oh, I feel stupid now. I figured out a solution. If I put:
Code:
helmet.x = x;
helmet.y = y;
in the end step event, it works.
 
Top