3.2 KiB
Executable file
3.2 KiB
Executable file
Section 05 - Lesson 06 | Plane Movement
Notes
- the more complex the collision shape the more computations
- if you concentrate on good games, you'll notice the collisions are actually straightforward
collision shape
adding a collision shape
- click on root node
-
add child CollisionShape2D
- pane scene->collision_shape_2D
-
pane inspector->CollisionShape2D->Shape
- select new CircleShape2D
- use shape handles to adjust
issues with collisions
- we want the collision shape to be good
- but the more complex the collision the more computations
- focus on the game flow, not perfecting the modeling
circle shape resource
- click inside the Shape dropdown on the CircleShape2D item
-
it will open up and show you details about CircleShape2D
- radius
-
resource
- local to scene
- path
- name
- currently the resource is embedded in the scene
if you want to save the resource for reuse
- click on the arrow next to the Shape dropdown
- click save or save as
add a script
- SELECT THE ROOT NODE "plane"
-
click on the Scene green plus to add a script
file:../../_share/media/img/albert/section-05/lesson-06/ex_01a.png
in dialog
- template: select Node default
- built in script: off
coding
-
in a phsycis body we just give vectors
- let the physics engine deal with positioning
-
CharacterBody2D has a velocity variable which you can set
-
Vector2D velocity
- x, y
- how much we want to move in x and y
-
function bool move_and_slide()
- updates our position
- updates the velocity if we collide with something
-
after move_and_slide has been invoked we call other funcitons
- is_on_ceiling
- is_on_floor
- etc
-
-
upDirection method sets what is "up"
- default x: 0, y: -1
- (0, 1) ceiling is now floor
- (1, 0) the left side is the ceiling
default gravity
- you can access gravity from Project Settings
var _gravity: float = ProjectSettings.get("physics/2d/default_gravity")
manipulating physics nodes
- use _physics_process instead of _process
- process is invoked every frame
- physics process is invoked at about half that rate
creating boundaries
create barrier scene
initialize the scene
- create a new scene
- don't select one of the default nodes as the root
- use the + symbol in Scene to select a StaticBody2D as the root node
add boundaries
- create 2 CollisionShape2D nodes
- on each set shape to WorldBoundaryShape2D
-
lower node
- move the boundary to the bottom of the viewing area
-
top node
- move the boundary a little bit above so as to give the plane some room to bounce through the ceiling
-
click on the Shape dropdown of WorldShape2D to open additional values
- set the direction to down
- in Normal, change y from -1 to 1, so it points down instead of up
- save scene
add barrier to game scene
- instantiate as a child node in the game scene