Hello! I’ve been trying to script a 2D character controller using WASD/arrow keys (I need the character to be able to move in all four directions). I’ve been playing around/looking for various solutions but I can’t seem to get it to work that I want to?
The current script that I have actually moves the character but it’s locked into position - like it’ll move one unit and then automatically return to the starting position. I know what the problem is but I don’t know how to fix it?
public float range;
public void Update (){
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
float xPos = h;
float yPos = v-4 ;
transform.position = new Vector3 (xPos, yPos, Time.deltaTime);}
I understand that I need to somehow replace (or add) the character’s position within the Vector3 segment but I don’t know what terms will bring it up.
If this isn’t the best way to make a simple WASD controller, then could somebody suggest a better alternative? I should also note that I would like to keep the choppy movements that getAxisRaw gives me!
Thanks in advance!