Godot Platformer Lesson 1a: Player Movement¶
Summary¶
This lesson covers player movement and collision with walls.
Prerequisites¶
Godot Installed
Video¶
Errata¶
link: https://www.gdquest.com/tutorial/godot/2d/your-first-game/chapter/1-player-and-enemy/
For this video there is a missing segments at 32:21 when the project window settings are changed.
Definitions¶
- Class:
A class is a recipe for an object (like a player or item). Classes can be extended to create child classes. A child class inherits traits of the parent while adding traits of its own. In biology ‘human’ would be a child of the class ‘mammal’. Child classes can also change some of the parent traits. If the class ‘mammal’ is defined as walking on land then the child class ‘whale’ changes that trait to swimming in water.
Code¶
Repository: https://github.com/los-alamos-steam-lab/GDQuest-Platformer/tree/1a-player-movement
Actor Code¶
extends KinematicBody2D
class_name Actor
export var speed := Vector2(300, 1000)
export var gravity := 3000.0
var velocity := Vector2(0, 0)
func _physics_process(delta):
velocity.y += gravity*delta
velocity = move_and_slide(velocity)
Player Code¶
extends Actor
func _physics_process(delta):
var direction := Vector2(
Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
1
)
velocity = speed * direction