0 votes

Hello! I am a beginner in game engines, godot is the first one i used. I have used this game engine for like 3days now, and i am trying to make a customization menu. The problem is the hair sprites have different dimensions,because the player can choose from either very long hair or very short.
I have a variable called "hairnum" for the model of hair. For example, for hairnum=1 i want the y position to be 15, and for hairnum=2 i want the y position to be 20. How do i do that? I tried searching on youtube or chrome but i didn't really understand. I'm saying again that i do not know a lot, i am only at the beginning, so i appreciate any help.

in Engine by (92 points)

1 Answer

0 votes
Best answer

You could make an array with the y positions in it

var hair_positions = [15, 20, ...]

then if hairnum changes get the position

sprite.position.y = hair_positions[hairnum]

Note that hairnum has to be 0 to get the first position in the array, 1 for the second and so on. Or subtract 1 like

sprite.position.y = hair_positions[hairnum-1]
by (1,456 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.