Hello everyone!
Does anyone know how I can make a Geiger counter needle rotate based on the distance between the player and some “radioactive material”?
Should I use a Line Trace or OnBeginOverlap for this?
I’d also like the needle to have a slight left–right jitter so it’s not completely static — it should still rotate based on distance, but when the value isn’t changing much, it should wobble a bit for realism.
Additionally, how can I make it so that each time the needle updates (for example, every Tick), it plays a clicking sound like a real Geiger counter?
I’m going to kind of skim because this is multiple questions, let me know if there’s anything you’d like a more detailed explanation on!
Have a collider sphere on the “Radioactive_Actor” that goes out to the furthest reaches of where it would affect the player. Then use OnBeginOverlap to start a SetTimerByFunction, with an update speed relatively low, let’s say .075.
The connected function should check distance between the “Radioactive_Actor”'s Actor Location and the PLAYER’s Actor Location
(Use a Vector minus Vector node and then a Vector Length node).
Then you’ll take that distance and do math in a Function- make sure the String on the Set Timer By Function matches the function’s name exactly!
From here, with that number you could do a load of things, it all depends on how YOU want it to behave! As far as putting a dial on the screen you can use a UI widget of some kind or another (Progress bar type, I believe, but you’d need a custom one I don’t think UE5 comes with one). If you wanted the Geiger counter to be in the environment of the game, that’s something else entirely.
I got it working with line trace, and yeah that “needle” is in 3D form not UI. One thing i can’t get is sound it plays but it doesn’t stop. Here is the Screenshot, i probably didn’t do something right, but i’m new in Game Development and i have spend so much time on getting this system to “work”
Maybe try a check using any of these Floats- if it’s above 0 or whatever threshold, play sound, if it’s below 0, stop sound. But of the ways you could be playing sound, I don’t see any?
One thing about it is that the first time it rotates, it does it by Timeline, but next time it just snaps to that rotation, and besides that i would like to make that needle doesn’t stay static, it has left–right jitter
To add play into the needle you’re going to need to add a “Set timer by event”, and off of the “Completed” part of the timeline, run that, and every .2 seconds (looping) using the “Set Timer by event” , use “Random Float In range” to get a float between -5 and 5 degrees and have it add that to the relative rotation.
Here I first check if overlapped actor has a radioactive tag, then add the actor to an array var. Next it starts a timer with event which checks the distance to the most recent rad source, does some sloppy math, and updates relative rotation of a needle mesh I attached to front of camera. Using a UI widget would probably be a better idea tho..
Finally when the large sphere ends overlap, I check if actor is in the rad source array and remove it: