I have a spaceship I’m moving around on the screen, when the player moves the ship, it rotates on its axis. However, when the ship meets a clamped boundary(on the x-axis) it abruptly stops. How do I make it so that the ship will still rotate when meeting the clamped boundary?
void Controls(){
Rotate();
MoveShip();
}
void Rotate(){
player.rotation = Quaternion.Euler((player.velocity.y * -pitchAngle), 0f, (player.velocity.x * -bankRotation));
}
void MoveShip(){
float moveVertical = Input.GetAxis("Vertical");
float moveHorizontal = Input.GetAxis("Horizontal");
Vector3 bank = new Vector3(moveHorizontal, 0f, 0f);
Vector3 pitch = new Vector3(0f, moveVertical, 0f);
player.AddForce(bank * bankSpeed);
player.AddForce(pitch * pitchSpeed);
player.position = new Vector3(Mathf.Clamp(player.position.x, xMin, xMax), Mathf.Clamp(player.position.y, yMin, yMax), 0f);
if((player.position.x == xMin) || (player.position.x == xMax) || (player.position.y == yMin) || (player.position.y == yMax)){
player.velocity = new Vector3(0f, 0f, 0f);
player.angularVelocity = new Vector3(0f, 0f, 0f);
}
}