What is the fastest way to get distance between two objects? Godot 4 Tutorial - GDScript Perfomance @nanotechgamedev
What is the fastest way to get distance between two objects? Godot 4 Tutorial - GDScript Perfomance  @nanotechgamedev
Uploaded June 2024 | Updated November 2026, 4 hours ago
NOTE: Although this video shows you how to benchmark your functions, the fastest way to optimize your code can be caching information outside of the looping methods, and depeding on the amount of operations executing inside the same looping function the math can drastically improve the perfomance.

On this project if I stored the global position outside of the looping function and execute the math inside the same looping function it runned at ~0.029 seconds, that's almost 10x times faster than what I showed in the video at ~0.281 seconds;

-
So I wanted to make sure what was the fastest way to check the distance between two objects, this is a replacement to physics collision systems as we can assert if a object is close enough to another it means we can do something, so this is way faster than using geometric physics with meshs colliding, because it's just based on distance, for RTS and games where you need this type of information, this can be quite handy,

But how do you even optmize functions, find out which one is the fastest or test them? In this video I also will be working with a Callable to inject itself as a argument in oder to bechmark all the functions you want, this way you can test a lot of different functions very easily, if you never used Callables or find them confusing, this video should provide you an example of how to use them.

This was prompted by a comment, so don't be afraid to comment on my videos as you can provide useful insight to many different people, thanks for the comment, I believe it works faster, I just could test it with C# or C++ yet, but I believe it is faster, with GDScript however, this works a little different,

Check the full video, subscribe and comment,
What is the fastest way to get distance between two objects? Godot 4 Tutorial - GDScript PerfomanceRts in Godot Part 48 : Building the Main Ui Part 2/2 for an Rts Project Made In Godot from ScratchRts in Godot Part 7 : AABB Mouse Selection for an Rts Project Made In Godot from ScratchHow I made an RTS Camera on Godot 4 (Part 1) : Coding From Scratch - Making an RTS SeriesRts in Godot Part 29 : Rolling Back! Catching up to Part 26 P3 - Rts Project In Godot from ScratchGodot Looking at Tutorial with bones : How to bones pose in Godot - Rotation towards AI target : RTSNew Godot Release Again!!! The Improvements in 4-4 Beta 1 - New Features ReleaseA Godot Gamedata System : Data Structures - (Part 3) - Making a RTS SeriesFrom scratch make a 3D hp bar shader in Godot: Making an RTS in Godot - Shader TutorialRts in Godot Part 25 : Rts Minimap for an Rts Project Made In Godot from ScratchHow to improve Godot Physics Perfomance? Heres an optmization trick - Making an RTS in GodotRts in Godot Part 46 : Ui Finished and Iterations for an Rts Project Made In Godot from Scratch
Nanotech Gamedev |

What is the fastest way to get distance between two objects? Godot 4 Tutorial - GDScript Perfomance

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER