== Game Ideas == Dead user - A command-line game where you investiage odd behaviour on sites/forums. Usually centered around usernames that have long been inactive or associated with people known to be deceased. == Programming == == Static functions == It is possible to set callbacks to a static library by supplied said library object as a parameter to the function {{{gdscript static func libfunc(this_lib, otherparam): ... var t = Timer.new() t.connect("timeout",this_lib,"other_lib_function") t.start() static func other_lib_function(): pass }}} Static functions must be called without being instanced. So for example: {{{gdscript const STATIC_LIB = preload("res://path/to/staticlib.gd") func _ready(): STATIC_LIB.somefunction(self, ...) }}} So we just have to preload them. Ideally in some global instance so we don't have to preload them everywhere we need them == Callbacks and anonymous functions == In godot4 (not 3) we can make an anonymous function like so {{{gdscript var f = func (params): pass }}} In godot3 we create and call a function reference like so {{{gdscript var fref = funcref(obj, 'func_name') fref.call_func() }}} In godot4 {{{gdscript f.call() # i think, need to check again }}} == 3D Double precission == To use double precission for world cooridnates calculations (to avoid 32bit float imprecission errors and weirdness) it is necessary to compile the engine from source with `precision=double` parameter in the `scons` build command == Collision layers and masks == Collision layers define where an object is placed And the mask defines what `layers` the object will `scan` for collision. This is very usefull for defining more intricate interactions between objects and Area2D/3Ds. This also means that deselecting `layer 1` on the player causes all `Areas` to silently ignore the player, leading to a mild confusion as to whats actually happening. === Vector math in programming === ==== Getting the direction vector from 2 points in 3d space ==== To calculate the direction of 2 points (called just a vector in regular math but not in programming) we take the point A and point B and subtract them from eachother and normalize them. The order matters, because we get either the direction from A to B or from B to A. So {{{gdscript var A = Vector3(1,1,1) var B = Vector3(10,10,10) var C = A - B var C_Dir = C.normalized() }}} In this way, if we have the lights position, and the position of a fragment inside a 3d object, we can implement proper cell-shading ==== The most basic toon shading ==== In Godot4, we have a `light () {}` function we can write to. This function is called for every pixel for every light in the scene. {{{glsl void light() { vec3 dot_prod = step(.2, dot(LIGHT, NORMAL)); DIFFUSE_LIGHT = vec3(dot_prod); } }}} void step(edge, x) _step_ generates a step function, that returns 0.0 if x[i] < edge[i] and 1.0 otherwise The above basically paints the mesh white where the light is, and black (or whichever color is used for shadows) on the shade side of the light source. To better shade the object, use the _smoothstep_ function ==== Dot products ==== The reason we use dot products is better explained by this website: https://www.mathsisfun.com/algebra/vectors-dot-product.html The reason we use dot products has to do with the change of the vectors direction. If we just add the x components of the LIGHT and NORMAL, we also get a slight change in direction along the x axis of the light + the normal of the mesh. So a dot product gives a good way to combine the vectors and produce a scalar value to represent this result, which we can then conviniently use in the step function to create a hard edge between the light and dark side of the object. ==== Outline shader ==== Pretty simple in Godot4 actually, just do not use the same shader material for multiple objects because the values will become all wonky. Add a second pass and look into the gdshader.fossil repository for the outline.gdshader. Attach it and there you go. Requires the vertices to be offset from their center. Godot4 also allows us to set render modes to unshaded and cull_front which is equivalent to duplicating the verticies and culling the front faces like in blender. To get nice outlines on models, the model must have separated objects. (Not just 1 whole complex mesh body) .