- Home /
New input System GetAxis alternative
Hi, I'm making a game where my player needs to accelerate so I need the vector2 to go smooth from 0 to 1, now it just goes from 0 to 1 instantaneous like the old "GetAxisRaw", setting the mode too analog does not work. Is there a way I can make it go smooth like "GetAxis"? Thx for your answer!
Answer by Pokedlg3 · Dec 21, 2020 at 12:53 PM
You can use transform.Translate and time.deltaTime to soften the effect of GetAxis, look at an example:
if(Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
{
transform.Translate(10*Time.deltaTime,0,0);
}
if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(10*Time.deltaTime,0,0);
}
if(Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
{
transform.Translate(-10*Time.deltaTime,0,0);
}
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(-10*Time.deltaTime,0,0);
}
the Time.deltaTime, leaves the movement smooth, replicating the effect of GetAxis, now if you want to get the effect of GetAxisRaw, just remove Time.deltaTime.
if(Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
{
transform.Translate(10,0,0);
}
if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(10,0,0);
}
if(Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
{
transform.Translate(-10,0,0);
}
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(-10,0,0);
}
Your answer
Follow this Question
Related Questions
Smooth transition for GetAxis, when pressing opposite direction 1 Answer
Get smooth input when Time.timescale == 0 1 Answer
Animation speed control - no smooth animation on slow down 3 Answers
2d camera help! 0 Answers
Turn page, smooth rotate 1 Answer