gdquest-demos / godot-kickstarter-2019

Create your Own Games with Godot, the Free Game Engine: sources from the January Kickstarter project from GDQuest
MIT License
244 stars 270 forks source link

Feature/demo platformer 2d #58

Closed johnnygossdev closed 5 years ago

johnnygossdev commented 5 years ago

Hello!

I'm in the middle of refactoring the platformer demo. You can see a todo list and progress in #57

I'd like some advice on some things before cracking on again.

  1. For the Player and Enemy, should I proceed with a StateMachine as in the Hook demo?
  2. I'm having trouble with the moving platforms. To align the Player with them, sync_to_physics seems to be necessary but it's not usable with move_and_slide so I'm unsure how to do this properly.

Please also offer any other feedback. This is also a learning experience for me as I learn to stick to the guidelines 😄

Cheers!

NathanLovato commented 5 years ago

Just fixed the moving platform issue. Here's the explanation:

The issue was that the floor's velocity (platform here) is only transferred to
the character if move_and_slide_with_snap's stop_on_slope argument is `false`.

stop_on_slope seems to stop the character's movement if it has no horizontal
velocity and the floor's normal is < a threshold angle to the floor_normal
parameter, even if it's horizontal in our case.

To preserve stop_on_slope on slopes, I've introduced a Raycast2D that only
detects platforms.
NathanLovato commented 5 years ago

Regarding the code style/guidelines, would you like me to do e.g. part of a script, or part of the project to give you a headstart + example? The code has some no-nos to me at this point.

johnnygossdev commented 5 years ago

Thanks for that Nathan.

There are some parts of the code that are left over from the original demo that I haven't touched yet. I was planning on going over the scripts in more detail after everything was working using the guidelines but an example would be helpful if you have time.

NathanLovato commented 5 years ago

There you go, I just rewrote the code for the Player script. There's more refactoring to do to show good practices: the physics layers and masks are a mess, so the original code relied on things like having the bullet get its parent and making it an exception for collisions. Anyway, the player is the most complicated bit here. from there, I think we could make some more gameplay improvements, but it'll be part of the polishing phase. I'd port all the code to fit the guidelines at this point.

Regarding moving platforms, I'd also remove the code to use an animation player too, as that way, you can directly move the platforms in the editor and even use the new animation autokey feature to make the platforms move exactly where you want.

johnnygossdev commented 5 years ago

That's great thanks for that! I'll work on the rest of the scenes today.

johnnygossdev commented 5 years ago

The other scenes should be better now and I've tidied up the stage.

I wanted to use Path2D for the moving platforms as I thought moving the path in the editor would make intuitive sense but the paths stop working when the KinematicBody2D is set to sync_to_physics so I used an AnimationPlayer instead. Still sad about that one.

NathanLovato commented 5 years ago

I just tweaked some tweaks. It's looking great to me! Do you still want to change anything or is it good to merge?

johnnygossdev commented 5 years ago

Great! If you're happy with everything then it's all good!