Skip to content

Appendices & bibliography

Nils Meijer edited this page Mar 21, 2024 · 5 revisions

Behaviour tree

A way to design AI behaviour, using a tree-like structure. The tree is built from a set of different node types. There is one “root node”, from which all other nodes are run. In my implementation, 2 different composite node types are being used.
  • Sequence node: all child nodes have to return SUCCESS. Otherwise, if any child returns FAILURE, the node fails and stops checking the child nodes, and returns FAILURE itself.
  • Selector node: if any child node returns SUCCESS, the node stops looping through the children and returns SUCCESS itself.

Wheel collider

A special collider for vehicle wheels [2]. Wheel collider is used to model vehicle wheels. It simulates a spring and damper suspension setup, and uses a slip based tire friction model to calculate wheel contact forces. Wheel's collision detection is performed by casting a ray from center downwards the local y-axis. The wheel has a radius and can extend downwards by suspesion distance amount. The wheel is controlled with motor torque, brake torque and steer angle properties. Wheel collider computes friction separately from the rest of physics engine, using a slip based friction model. This allows for more realistic behaviour, but makes wheel colliders ignore standard PhysicsMaterial settings. Simulation of different road materials is done by changing the forwardFriction and sidewaysFriction based on what material the wheel is hitting.

Mildots

A MIL-Dot reticle refers to a standard, specific pattern of duplex crosshair reticles with four small 0.25 mil diameter dots placed along each axis. These dots are arranged to allow for range estimation. A trained user can measure the range to objects of known size, determine the size of objects at known distances, and compensate for both bullet drop and wind drifts at known ranges with a MIL-Dot reticle-equipped scope [3].

Picture18

Drag coefficient implementation

private void UpdateShellsVelocity()
{
    foreach (Shell currentShell in _firedShells)
    {
        double deceleration = GetDeceleration(currentShell.RB) * Time.deltaTime;
        currentShell.RB.velocity -= currentShell.RB.velocity.normalized *    (float)deceleration;
    }
}
private const float AIR_DENSITY = 1.2f;
private const float SHELL_FRONTAL_AREA = 0.035f;
private const float DRAG_COEFFICIENT = 0.1f;

private static double CalculateDragForce(Rigidbody rb) => DRAG_COEFFICIENT * 0.5f * AIR_DENSITY * Mathf.Pow(rb.velocity.magnitude, 2) * SHELL_FRONTAL_AREA;

private double GetDeceleration(Rigidbody rb)
{
    double dragForce = CalculateDragForce(rb);
    Vector3 currentVelocity = rb.velocity;
    Vector3 inverseVelocity = currentVelocity.normalized * -1 * (float)dragForce;
    double deceleration = currentVelocity.magnitude - inverseVelocity.magnitude;

    deceleration /= rb.mass;

    return deceleration;
}

My implementation of the drag coefficient formula. For every shell that has been fired and is still active, the drag force is calculated and applied to the current velocity. A mechanical engineering student/friend explained the formula as I am not very skilled in physics/math so I asked him for help, after which I did my own research and attempt at implementing it. Eventually, he helped me a bit with the implementation.

Bibliography

[1] The Engineering ToolBox, “Drag Coefficient,” [Online]. Available: https://www.engineeringtoolbox.com/drag- coefficient-d_627.html.
[2] Unity, “Wheel Collider component reference,” Unity, 23 06 2023. [Online]. Available: https://docs.unity3d.com/Manual/class-WheelCollider.html. [Accessed 29 06 2023].
[3] Trijicon, “Advanced Mil-Dot: Estimating Distance Using Your Scope,” 28 08 2019. [Online]. Available: https://www.trijicon.com/community/post/how-to-use-trijicon-accupoint-mil-dot-riflescopes#:~:text=A%20MIL %2DDot%20reticle%20refers,to%20allow%20for%20range%20estimation
[4] C. Simpson, “Behavior trees for AI: How they work,” 18 07 2014. [Online]. Available: https://www.gamedeveloper.com/programming/behavior-trees-for-ai-how-they-work. [Accessed 05 2023].
[5] S. Castro, “Introduction to behavior trees,” 17 08 2021. [Online]. Available: https://robohub.org/introduction-to- behavior-trees/. [Accessed 05 2023].
[6] M. Pêcheux, “How to create a simple behaviour tree in Unity/C#,” 2 11 2021. [Online]. Available: https://medium.com/geekculture/how-to-create-a-simple-behaviour-tree-in-unity-c-3964c84c060e. [Accessed 05 2023]