How to use the function SphereOverlapActors?
I am using this function to detect the targets of an attack, but it is detecting the targets beyond the radius of the sphere specified by me, in this case, 1.0f.
In this image above I show the distance of the attacker to the point of origin of the sphere and the distance of the attacker to the location of the detected target.
In this image above I show the function call and inspection of the radius and the position of origin of the sphere.
asked Jan 23 '19 at 03:34 PM in C++ Programming
As for an answer that doesn't technically answer your original question, but hopefully gets you up and running again, maybe try something like this:
(Put this wherever you need to check if enemies are within a certain range)
This approach should be very efficient, since it avoids doing any PhysX collisions checks. And since it uses the squared distance between the locations, there's not even any square root calculations involved. Nice and quick.
Again, I realize that this answer avoids your original issue and therefore doesn't actually answer your question, but I hope it's useful to you anyhow!
answered Jan 23 '19 at 06:53 PM
In the screenshot you posted, the largest error above 1.0 was the value 1.000123, which is definitely close enough for most gameplay purposes. (It's over by just 0.01%!)
Are you trying to correct such instances where the distance to the sphere is just slightly larger than 1.0? If so, I'm not sure there's much you can do about it. You do appear to be using UKismetSystemLibrary::SphereOverlapComponents correctly, so no worries there. The inaccuracy is probably due to limitations in how precise PhysX is willing to be, or perhaps even due to limitations in floating point precision.
At some point, you have to accept a certain margin of error. For gameplay purposes, 0.01% is probably close enough, right?
answered Jan 23 '19 at 04:09 PM
Here I created AActor instance and add data member USphereComponent and binding dynamic events on what will be called. Also here is OverlappedActors pointer of AActor vectors represents overlapped actors binding dynamically on generated overlap events.
You may check for more using FNumberFormattingOptions struct that exists to create more precised float conversion explained by Rama on wiki: Here
Follow this question
Once you sign in you will be able to subscribe for any updates here