Spaceship goes out of the screen. Pls help

I’m trying to do the Space Shooter tutorial in version 5.4 but found an issue and don’t know how to fix it. I’m completing the tutorial for PC. When i move the spaceship to the border of the screen, it keeps going I already used the Mathf.Clamp but it just slow down the process. please help

your code works just fine. the problem about the ship slowly moving ACROSS the borders is caused by a never resetting velocity. once your ship hits a border you have to make sure it´s velocity in this direction gets either reduced or competely negated.

Easy way to solve

  • Create Box Colliders on the bordes of your screen
  • And make the ship collide with them

Hope it works