So I have tried both Velocity and addForce but I'm not getting the result I was expecting which makes me wonder if I fully understand what they do.
Move script (test script 1)
void Update () {
if(Input.GetKeyDown(KeyCode.Space)){
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
if(Input.GetKeyDown(KeyCode.A)){
rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
}
if (Input.GetKeyDown(KeyCode.D)){
rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
}
}
Move2 script (test script 2)
void FixedUpdate() {
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
rbody.velocity = new Vector2(x*speed, y*speed);
}
Both scripts are used independently.
Velocity when I press the key down (D or A) it stops after short time but addForce seems to do the same while that is set in FixedUpdate() or Update(), which is confusing as I thought it would keep it moving till the key was released? I have also found that if I press D it moves then stops but if I release D and press again and repeat the player does not move until I press a different move direction. Any ideas?