#Help with tile movement player

12 messages · Page 1 of 1 (latest)

autumn bobcat
#

I'm attempting to create a player movement system where the direction is determined by the last pressed button. For example, if I press the left arrow key, the player moves left, then if I press the right arrow key while still holding the left arrow key, the player should switch direction and move right. If I release the right arrow key while still holding the left arrow key, the player should turn left again.

I've tried several codes using 'for' loops, but none seem to work correctly with tile movement.

here is the code: https://pastebin.com/QBwMiiam

vagrant patrol
#

Lines 47+48, you are getting the input "strength", which as you are using a keyboard would just be 1. If you press both left and right, both will be 1 and the horizontal input would be 0.

#

If you wanted to do the action you wanted earlier, you would probably need to use Input.is_action_pressed and store which action has been pressed first, left or right. Then if the other one is pressed, reverse the direction.

autumn bobcat
autumn bobcat
#

Is there any way to make this for code work for tile-map movement?

vagrant patrol
#

If I was doing this, I would be using tweens to animate the movement and set the start and end positions to the center of the tiles, and use that instead of processing the movement every frame

autumn bobcat
#

I tried this guide before, but the character would be shaking

#

the camera glitches

#

but I don't know if it's because they used area2d instead of characterbody2d

#

I'll try to do this guide with a characterbody and see if the camera do a little shaking every step

vagrant patrol
#

Maybe turning on camera smoothing would work as well!