Hello. In my game the player is free falling while still can redirect its direction with a jetpack propulsion. The jetpack moves my player in two directions alone: rigth&up or left&up. With the below code I can make my player to move as expected on the screen but for unknow (for me) reasons velocity on X axis never changes from zero while Y axis increases as expected. The former means that velocity on Y remains even after the button is released and until gravity stops it to starts falling once again, on the other hand the horizontal movement stop as soon as the button is released since the X axis velocity never increases its value not even while the movement button is pressed.
void Update()
{
if (Input.GetKey(KeyCode.D))
{
_isRight = true;
}
else
{
_isRight = false;
}
}
void FixedUpdate()
{
if (_isRight)
{
_rb.AddForce(new Vector3(10, 5, 0), ForceMode.Impulse);
}
}
I also tried to just directly increase the velocity value by adding a vector each frame but got the same behavior gameObject moves just fine on the playmode screen but the X axis velocity never changes from zero so the gameObject instantly stops on button release while the Y axis velocity continues until gavity stops it as expected.
_rb.velocity += new Vector3(10, 5, 0) * 20 * Time.deltaTime;
As I said it is a free falling gameObject and there is no other objects in the scene so no way it is cuz unnoticed collisions.
Thanks for your answers and hope you can understand my problem since English is not my native language.