Hello, I just made this simple script which makes my gameObject moves in diagonal directions. D key for right/up movement and A key for left/up movement. I want the movement to continues until gravity stops it and gameObject starts to falling to the ground. This happens just fine with Y force, the gameObject keep ascending til gravity makes its job but for unknow reason X force just instant stops once key is released.
private float _forceX = 10f;
private float _forceY = 5f;
void FixedUpdate()
{
KeyboardController();
}
void KeyboardController()
{
var _rb = GetComponent<Rigidbody>();
if (Input.GetKey(KeyCode.D))
{
_jetpackParticle.Play(); // Parcticle system
_rb.AddForce(new Vector3(_forceX, _forceY, 0), ForceMode.Impulse);
_anim.SetBool("isMirrorFlying", false); // Animator
}
else if (Input.GetKey(KeyCode.A))
{
_jetpackParticle.Play(); // Parcticle system
_rb.AddForce(new Vector3(_forceX * -1, _forceY, 0), ForceMode.Impulse);
_anim.SetBool("isMirrorFlying", true); // Animator
}
else
{
_jetpackParticle.Stop(); // Parcticle system
}
}
Also, when checking the info section on the rigidbody component I can see how speed on Y is increased while speed on X keeps at zero even when the gameObject is moving on X axis on the playmode screen.
Thanks!