Mid air "sprint"

Hi all,

I’ve got a problem, as usual :\ .

I’d like to do that when I press the x key while going right or left (it’s a 2D game) in mid air, I do a sort of sprint PlayStation All-Stars Battle Royale / PSASBR: Dante Combo Exhibition HD 2 - YouTube like the one at 0:37.

if (Input.GetKey(KeyCode.RightArrow)) {
	transform.Translate(Vector3(1, 0, 0) * Time.deltaTime * walkspeed);
	if (Input.GetKeyDown("x") && sprintcount == 0) {
		rigidbody.AddForce(10.0f * gameObject.transform.right, ForceMode.Impulse);
		sprintcount +=1;
		}
	}

this is my code, but it doesn’t work like I would like it to do. I’d like to make the character go straight like in the video.

You’re combining Translate with AddForce, which causes unpredictable results.

You only use AddForce if you are going to use the physics engine with this game, if not then Translate is fine.

You mean like this?

transform.Translate(Vector3(5,0,0), ForceMode.Impulse);
because it doesn’t work, it says
No appropriate version of ‘UnityEngine.Transform.Translate’ for the argument list ‘(UnityEngine.Vector3, UnityEngine.ForceMode)’ was found.