Changing from linear acceleration to non linear

Hi, I might be overthinking this but with keyboard when you press either a or d (left or right) the so called xThrow is increasing at constant rate until it hits either 1 or -1.

I don’t know if it was assigned to us to implement non linear increasing of that rate (like it is shown on the video at some point) but I wanted give it a try anyway.

So I wanted that players with a keyboard could make more subtle movements. I’m trying to replicate same behavior that you would get in some games when you are scrolling long list of items. It starts slowly and then it speeds up the longer you keep pressing up or down.

I figured in this case this is what I want basically

In my code I did

private void HandleInputs()
    {        
        float xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
        float xThrowFinal = Mathf.Pow(xThrow, xThrowModifier) * Mathf.Sign(xThrow);       

        float xOffset = xThrowFinal * speed * Time.deltaTime;

        float xRaw = transform.localPosition.x + xOffset;
        float xFinal = Mathf.Clamp(xRaw, -boundary, boundary);

        transform.localPosition = new Vector3(xFinal, transform.localPosition.y, transform.localPosition.z);
    }

Now I can achieve pretty much what I want by changing input sensitivity in project settings.

Any thoughts or if anyone also implemented this I’d be happy to see your solution :slight_smile:

It seems to work like I want but my coder instinct says there might be a better way to do the same thing.

EDIT: After some time spending time outside and coming back to this I have come to conclusion that what I made is just making it worse :smiley: Technically it works but in practice and in this kind of game it just doesn’t feel right. Time to move on, nothing to see here :smiley:

EDIT 2: And now watching that video again I realized that non linear graph was referring to position change which is of course correct. Honestly, I don’t know how I didn’t see that in the morning. Should feed my brain more fresh air I think :smiley:

Hi,

First of all, good job on trying to solve a problem. It does not matter if the result does not look as expected. You had an idea, you tested it.

I did not test your code but by reading it, I’m wondering if you set the start time to define after how many seconds the player will move with full speed. Your diagrams are lacking the time axis but maybe I’m simply missing something.

Privacy & Terms