In a modified version of the side scroller template, I made a platform that the character can go through from the bottom. Now I want to implement a mechanic where it can go through from the top when the player quickly pushes the thumbstick down. I don’t just want how far it reaches its farthest point down, I want the speed at which it gets there. How would I get that?
I don’t think there’s anything in the Engine to handle this for you… but it seems simple enough to build your own.
I’d say you’re wanting acceleration, rather than speed. So speed = distance / time. Acceleration = change in speed / time.
When you process thumbstick inputs, you get normalised values between -1/+1, with 0 being no movement. As you receive a value, push it to an array - set yourself some limit on the number of items in said array. Also, if you’re tracking positive values and the next one received is negative, then empty the array and start the tracking again (unless you want to track oscilations!). For what you’re after, you’ll also only want to track the values in one direction, so if you receive 0.4, 0.5, 0.6 but then 0.2, then you know the thumbstick is being released (or moved back to the middle) and no longer in the same direction - so empty the array and track the new direction.
You’re also going to want some timestamp or delta, so maybe a simple struct with two properties, one with the thumbstick value and the other the timestamp.
After you’ve received your range of inputs (your samples), for say 5 values, you need to process the change. Quickest way, check the difference between the first and last values (largest - smallest) and the same with the timestamp (newest - oldest = time difference). Now you can do something like: thumbstick value change / time difference = approximate acceleration/speed.
You can of course do the check on every 2nd item, thus giving you the speed between the two and then another check between these speeds gives you the acceleration. So item 0 against 1 gives speed A. Item 1 against 2 gives speed B. Speed A against B gives acceleration. How often you check your samples and against what time delta, is up to you.