User Tools

Site Tools


godot_notes

This is an old revision of the document!


Table of Contents

Part 1

  1. New scene: click 3D Scene, rename to 'world'
  2. Create floor. Add MeshInstance3D to scene
  3. Set Mesh type to 'New PlaneMesh'
  4. Change size. Transform → scale to 20
  5. Create collision mesh. Using the 'Mesh' top button, choose 'Trimesh Static Body'. That automatically creates a StaticBody3D of the correct type, and then adds a CollisionShape3D.
  6. New wall. Create another new mesh. This time the Mesh should be New BoxMesh'. Move walls to edge, set z to 20
  7. Tweak the wall height, 'y to the sky', set to 10
  8. Duplicate for the other three walls

Part 2

  1. New scene. Click + next to the world scene. Other node. Search for CharacterBody3D. Name it 'player'.
  2. Add subnode. Click +, search for MeshInstance3D. Set Mesh shape to Capsule shape.
  3. Fix the height. Transform, adjust Y to 1m.
  4. Select player node, add new node, Camera3D.
  5. Adjust Camera height to eye height.
  6. Create script. Select player node. Use script+/scroll button. Select a template for Basic movement.
  7. Add new variable. const TURN_SPEED = 0.05
  8. Add new code
if Input.is_action_pressed("ui_left"):
  self.rotate_y(TURN_SPEED)
if Input.is_action_pressed("ui_right"):
  self.rotate_y(-TURN_SPEED)
  1. Comment out the jump code
  2. In the world scene, drag the player scene into the world
  3. In the three dot menu (world scene), use 'Add Sun to scene', 'add environment to scene'
  4. In the player scene, use the Mesh button to add a 'Simplified Convext Collision Sibling' mesh to the player's MeshInstance3D
  5. Set up WASD controls in the Project Settings

Part 3

  1. Import a texture by dragging it into the file system.
  2. Select a wall. Use Geometry → Material Override. Select New StandardMaterial3D. Click the sphere. Expand Albedo. Drag the texture to the 'Texture' input.
  3. Find UV1, experiment with the sizing, approx 30 x 10
  4. Apply to floor/other walls.

Part 4

  1. Create new scene, other node: 'CanvasLayer', rename to 'ui'
  2. Create new node, AnimatedSprite2D
  3. Create new node, ColorRect
  4. In 2D view, size the ColorRect. Layout → Anchors → Bottom Wide. Set the colour to dark blue.
  5. Import wolfweapons.png
  6. Select Animated Sprite. Expand Animation → Sprite Frame. Click New SpriteFrames. Click it again to view the animation frame at the bottom.
  7. Rename default to 'knife_idle', set as default.
  8. Click grid, adjust, set up idle frame.
  9. Adjust position of animatedspirteframe in 2D view, use Transform→Scale to size up to 5
  10. Create new animation called 'stab'
  11. Add new stab animations, disable loop, set FPS to 16
  12. Click UI root node, add script. Enter the following code:
ui.gd
extends CanvasLayer
 
var ammo = 0
var current_weapon = "knife"
 
func _ready():
	$AnimatedSprite2D.animation_finished.connect(_on_AnimatedSprite2D_animation_finished)
 
func _process(delta):
	if Input.is_action_just_pressed("ui_select"):
		if current_weapon == "knife":
			$AnimatedSprite2D.play("stab")
		elif current_weapon == "gun":
			if ammo > 0:
				$AnimatedSprite2D.play("shoot")
				ammo -= 1
 
func _on_AnimatedSprite2D_animation_finished():
	if current_weapon == "knife":
		$AnimatedSprite2D.play("knife_idle")
	elif current_weapon == "gun":
		$AnimatedSprite2D.play("gun_idle")
godot_notes.1710764680.txt.gz · Last modified: 2024/03/18 12:24 by admin