What code should I use to walk FPS with WASD in Unity | SoloLearn: Learn to code for FREE!

0

What code should I use to walk FPS with WASD in Unity

5/9/2020 5:41:51 AM

Emre Uyan

2 Answers

New Answer

+1

Import Unity's FPS script module https://answers.unity.com/questions/315398/how-do-i-create-wasd-controls-for-a-fps.html https://docs.unity3d.com/ScriptReference/30_search.html?q=fps

0

Hey Emre, There's a few ways to go about doing this. I think the easiest would be to add a FirstPersonController component to the player (If I remember correctly, I believe you can import it from Unity's asset store). This has its own way of managing movement and should by itself use wasd by default to move the character. To make your own, I recommend checking out the Input class. https://docs.unity3d.com/ScriptReference/Input.html with the default method "Update", you can frequently check for any keys that are pressed on the keyboard, then do something when they are pressed (such as move a character on w,a,s or d). There are a few ways you can go about moving the character. Most likely, you would want something along the lines of: https://docs.unity3d.com/ScriptReference/Transform-position.html For that, I'd also recommend checking out my personal favorite method: lerp https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html Helps make it look smooth. *Lerp may look complicated at first though*