Gravity for gamepad axes?

I’ve noticed something about controlling my ship that was even mentioned in Instructor Hangout 4.2, it looks great with keys because of the gravity settings that don’t let it just SNAP back to zero throw, it lerps it smoothly… however, unless I move my gamepad in slow motion back to zero throw, when I let go fo a full throw -1 or +1 it snaps back without a lerp… and there is no gravity setting for gamepad axes…

How can I get my ship to gradually lerp back to zero throw when I release a thumbtack or slam into -1 or +1 throw so it doesn’t look so fake? It really breaks suspension of disbelief.

Hi Heath,

Do you use GetAxis or GetAxisRaw? Test the one which you haven’t tested yet.

I changed it from

xThrow = CrossPlatformInputManager.GetAxis("Horizontal");

to

xThrow = CrossPlatformInputManager.GetAxisRaw("Horizontal");

but that didn’t do anything to the behavior… did I misunderstand your suggestion?

You understood me correctly. Unfortunately, that was the only premade solution I had. Please feel free to ask our helpful community of students for advice in our official Discord chat.

If nothing helps, you could write your own universal solution. In this case, you would have to evaluate the user input. For example, you could define a control variable. If the value of GetAxis or GetAxisRaw is higher than 0, you would define it as 1 and assign it to the control variable, and if its lower than 0, you would define it as -1. Else 0.

You do not use the value returned by GetAxis or GetAxisRaw directly for the movement.

Then you could write a timer in, for example, Update(). For example: If the control variable is higher than 0 and the GetAxis or GetAxisRaw method returns 0, you start the timer and use the Mathf.Lerp or Mathf.Slerp function to gradually decrease the control variable until it is 0.

Use the control variable for the movement.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms