Skip to content

improved the player movement script and made some of its constants and variables static#17

Open
Sulucnal wants to merge 6 commits intoMaruno17:mainfrom
Sulucnal:improved-movements
Open

improved the player movement script and made some of its constants and variables static#17
Sulucnal wants to merge 6 commits intoMaruno17:mainfrom
Sulucnal:improved-movements

Conversation

@Sulucnal
Copy link
Copy Markdown
Contributor

When an horizontal movement key and a vertical one are both pressed at once, the player will move in the direction of the last key pressed instead of defaulting to the horizontal direction.

I also added inputs specific to the player's movements separate from the UI ones and changed the deadzone of the movement input from 0.5 to 0.1.

@Voltseon
Copy link
Copy Markdown

At first glance this appears to work as intended. However, it only appears to work as it simply ignores controller input.

Changing line 59 in player.gd to use the builtin ui inputs (which has controller support) with var input_direction : Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down", INPUT_DEADZONE) breaks the intended functionality in the same manner.

For print(last_direction) it is printing (0.0, 0.0) which can be assumed to be a case of floating point rounding. Because of this it is difficult to assume what the intended input direction is. It would probably be better to check which direction can be nullified based on which axis has a larger magnitude. For example you could compare the absolute value of the x axis to the y axis and nullify the smaller axis.

@NuriYuri
Copy link
Copy Markdown
Collaborator

I would also put the whole logic of deciding the player direction into a component that would return the new direction (and maybe hold last) so we can easily swap between dir4, dir8, dir360 :)

There is now a new constant called GRID_MODE in the Constants class that let you chouse between 3 modes of movements.

When the process_player_input function from the Player script gets the input_direction, it now goes through a _get_appropriate_direction function to get reassigned to a proper value depending on the movement mode.

IMPORTANT: For now, the input_direction conversion is the only thing working. The proper way to handle movement and animation outside of the "GRID_4" movement mode hasn't been implemented.
@Sulucnal
Copy link
Copy Markdown
Contributor Author

I tried to implement a function to do what you asked for but I'm not 100% sure if that's what you had in mind, so feel free to take a look at the _get_appropriate_direction function in the player's script whenever you have time.

@NuriYuri
Copy link
Copy Markdown
Collaborator

Not really. I did not ask to implement the dir8 or dir4 but make it composable.

Here's a video that would explain better what I had in mind: https://www.youtube.com/watch?v=74y6zWZfQKk

(Don't overwork yourself btw)

@Sulucnal
Copy link
Copy Markdown
Contributor Author

Sulucnal commented Apr 16, 2025

I imagine that in most cases, you'd want every overworld entity to move the same way as the player for the sake of consistency. In that case, wouldn't making it a component mean that we'd have to remember to attach the node we want not only to the player, but also to every single moving entity in our game?

@NuriYuri
Copy link
Copy Markdown
Collaborator

Entities should move with a velocity vector or something. This one in particular it's only about controlling the player movements with inputs

@NuriYuri
Copy link
Copy Markdown
Collaborator

I didn't know there was new commits. Remind me tomorrow to take a look please :)

@Sulucnal
Copy link
Copy Markdown
Contributor Author

Sure. However, movement animations haven't been re-implemented yet and I got too lazy to find a way to fix it so if you (or anyone else) want to give it a go, be my guest.

@NuriYuri
Copy link
Copy Markdown
Collaborator

It looks a bit better but there's few stuff that bother me. Can you give me write permission to your repository so I can work a bit on that as well?

@Sulucnal
Copy link
Copy Markdown
Contributor Author

I just added you as a collaborator.

@NuriYuri
Copy link
Copy Markdown
Collaborator

Nice, thanks :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants