I’m a beginner on UE and i’m facing a problem. I am probably not treating this issue as I should I guess so i’m asking your help
I followed a tuto to create a simple turret. Now I am trying to improve it.
I am trying to play a sound WHEN my turret is moving.
So my turret detect a target, then align to it ( by comparing “find look at rotation” between both actors and “get World Rotation” of the turret. When it is different, it align to it. That is working.
When i am far from the alignement, everything is OK. But when my turrent is aligned to the target, and the target is moving, I can’t find a way to detect the micro movement. All i have done is not accurate enought.
I tried to round the rotation vector and everything, but this is not accurate enought. Whether it is too round and i can’t detect the micro movement, whether it is not enough rounded and the alignement is always different. Look
The final print string is telling me if the two vectors a equal. So the turret align, I micro move, it micro re align, and sometimes it says TRUE, sometime it says FALSE, because it’s not accurate enought. I also tried with the “DOT” function but it’s not beter
How should I do ?
Thank for those taking the time to read me. Really.
Edit : here are the values returned by “Find look at Rotation” and “Get World Rotation” when both are align, there is a little difference
Don’t play the sound depending on the difference, play the sound for as long as you have to run the rotation code. Then stop it, when the rotation code stops.
For a micro rotation, the system won’t get a chance to play the sound.
Thank you for your answere Clock !
I’m not sure this will work, as the code for upgrading the turret rotation is running in continue since there is a target in the sphere of detection…
It’s made like this :
Find a target ( via sphereOverlapActors)
then it align to the target. So the sound is playing in continue if I do that
How about only playing the sound if the difference is greater than a certain amount. If it’s only moving in Z, well, that’s just a float. If it’s moving in all 3 axes, then you can use:
Thank you for having take time to try something, appreciate it !
Unfortunately, doesn’t work either.
The result after the ACOSd, when i’m moving ( so when the turret is aligning) varies from 0 to 0.027976, and when it is aligned and I don’t move anymore, the result is a number beetween 0 and 0.027976 ( and it can be 0.027976 too) so i can’t test this number because it can happen both when it’s moving or when i’m still
Ok, try that previous idea, but there is also this:
Measure the different between target locations. When you look at the player, you can extend a vector in front of the gun ( fixed distance ). Next time you look, extend the vector again, and look at the distance between them:
I think you will have the same problem if you run it every frame BTW, but at least you’re measuring a larger distance.