(A) Implemented unit collision and break algorithm using critical distance calculation; If two unit’s critical radius collide with each other, the emergency velocity diversion function is performed. The function will remove all velocity from direct collision course between the two units. It does this by projects each unit’s velocity onto a vector drawn between the two units. This projected collision velocity will then be removed from the unit’s velocity itself. Which force the unit to either divert away (if original velocity is not in direct collision) or stop moving entirely.
(B) Refactoring forces result from the difference functions to work better together, by treating the force as the targeting velocity itself rather than just velocity’s direction. Obstacle repulsion and target attraction are now both clamped to the same size, so that the only way for there to be a “sinkhole” would be if there is an obstacle directly between the target and the unit. After which, the unit’s attraction and repulsion is layered on top of the balanced equation, ensuring the push from movable units take priority.
This equation however seem to result in another “sinkhole” at the entrance of a balanced “tunnel” with obstacles on both side. Perhaps the targeting force should get a booster to always be higher than obstacle avoidance?
(C) Obstacle repulsion calculation is now performed as part of the background loop function in GameNavigator rather than calculated individually every frame by all units. As obstacles are near constants, delay of a fraction of a second should have little to no impact.