Godot
Physical Objects
A rigidbody is a physical object that falls, bounces etc.
A staticbody is a physical object that does not move.
Both of the above need to have the following child nodes:
- Sprite or AnimatedSprite (so you can see the object)
- Collision (to define the physical shape)
Create a physical object |
Use a button to apply an impulse |
Add and play animations (or more detailed explanation, including sprite sheets) |
Make a player that can jump
First you will need something for the player to stand on.
- Create a StaticBody2D node
- Add a Sprite2D node as a child to the StaticBody2D and set its texture in the Inspector
- Add a CollisionShape2D node as a child to the StaticBody2D and set its shape in the inspector
- Select the StaticBody2D and use the Move tool to move it to a good place in the scene
Now you can create your player:
- Create a RigidBody2D node
- Add a Sprite2D node as a child to the RigidBody2D and set its texture in the Inspector
- Add a CollisionShape2D node as a child to the RigidBody2D and set its shape in the Inspector
- Select the RigidBody2D and use the Move tool to move it to a good place in the scene
- Attach a script to the Rigidbody2D and save it
- Put this code in the script:
Make a top-down drivable car
Destroy object on collision
- Add the breakable object to the "breakable" group (from the Node tab next to Inspector)
- Add a script to the breaker object
- Connect the body_entered signal on the breaker object to its script
- Use this code instead of pass:
if body.is_in_group("breakable"):
body.queue_free() - In the Inspector for the breaker object, set Contacts Reported to 2 and Contact Monitor to On.
Make an object that can be dragged
- Create an Area2D node
- Add a Sprite2D node as a child of the Area2D and set its texture in the inspector
- Add a CollisionShape2D node as a child of the Area2D, set its shape in the Inspector, then adjust it to match the Sprite
- Attach a script to the Area2D node and save it
- In the Node tab (near the Inspector) find the input_event signal, and double click it, then choose the Area2D and click Connect
- In the script, add this code:
Play a sound
- Export the sound as .ogg file and put it in your Godot project folder
- Select the .ogg file in the FileSystem tab in Godot, and switch from Scene tab to Import tab
- Untick Loop, and click ReImport
- Switch back to Scene tab and add an AudioStreamPlayer2D node as a child of the node your script is on
- Drag the .ogg file as the Stream in the Inspector
- In your script, use this code to play the sound:
$AudioStreamPlayer2D.play()