Hi Folks,
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.
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);
}
}
void FixedUpdate() {
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
rbody.velocity = new Vector2(x*speed, y*speed);
}
So 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() which is confusing as I thought that would keep it moving till the key was released?
It also stops and I can press the key few more time with zero response from it which is very odd. Any ideas why?
Thanks.