gdo Flashcards
A Prefab in unity is called a
Scene in godot
The usual components of a player are
Animated Sprite, body, collider
res:// refers to
the base directory of the project
To get a component in a script, instead of using get_node you can also use
$NodeName
To create a scene
right click on the node and choose save node as scene
The root node is essentially a
viewport
Note: To change the viewports values go to
project -> project settings -> display -> window
To add resources to your file system
right click in file system -> show in file manager
and drag the resources into that folder that pops up
A sprite node automatically inherits all the
functionality of a Node2D
To give a sprite an image you must drag the image
into its texture field
Note: An image with multiple images together that form an animation uses the “Atlas Texture”
Note: If you want an animation, this needs to be an animated sprite
In godot the pivot point field is called the
offset
To add a new script to a node
right click -> attach script
To get the x and y lengths of the viewport, type
get_viewport().size.x
get_viewport.seize.y
To change the main scene (scene that renders when you press play)
Project -> Project Settings -> Application -> Run -> Main Scene
To set the position of using a vector, type
Vector2(x, y)
To rotate a node from a script, type
rotate(deg2rad(90))
The value of multiplying speeds by delta in the _process function is
that it will normalize the speed across different machines
To translate a node from the script, type
translate(Vector2(x, y))
To add a node to a node from a script, type
add_child()
To create an animated sprite
Add AnimatedSprite node
Set frames field to sprite frames
Add images to the sprite frames
Set animation field to the same name of the animation you used in the sprite frames
To get the mouse position, type
get_viewpost().get_mouse_position()
To run code if a click is happening, type
func _process(delta): if Input.is_mouse_button_pressed(BUTTON_LEFT): pass
To set and check the type of a node, type
my_node.set_meta(‘type’, ‘wall’)
my_node.get_meta(‘type’)
To access a variable from a different script, type
get_node(“../nodePath”).variable
To make a kinematicbody2d chase, type
const SPEED = 500
func _process(delta): var vec = target_position - self.position # getting the vector from self to the mouse move_and_collide(vec.normalized() * delta * speed)
You can edit the default physics in
project -> project settings -> physics -> 2d
To create a player, the structure of notes you want are
RigidBody2D
Sprite
CollisionShape
To create a building, the structure of notes you want are
StaticBody2D
Sprite
CollisionShape
An impulse is
a one time push of forces to a rigidbody
The difference between KinematicBody and RigidBody is
rigidbody is meant to be moved by physics forces
KinematicBody is moved by move_and_collide and move_and_slide
In order to move a KinematicBody2D while allowing it to collide, use
move_and_collide(vector)
To prevent a rigidbody from rotate after impact
set it to character mode
To start detecting clicks
Project -> project settings -> Type new name in top bar and click add -> Click plus next to new list item -> mouse button
func _unhandled_input(event):
if event.is_action_pressed(“Click”):
var soldier = SOLDIER_SCENE.instance()
soldier.position = get_viewport().get_mouse_position()
get_tree().get_root().get_child(0).add_child(soldier)
To spawn nodes
first convert it to a scene, then
var soldier = load(‘../Scene.tscn’).instance()
get_tree().get_root().get_child(0).add_child(soldier)
_unhandled_input is used
only to capture events that were not already captured by the event system
To get the distance between 2 positions
position.distance_to(building.position))