Player ship stuck in center

Hello, I am having an issue with my Player Ship getting stuck in the middle of the screen when testing the game.

The course I am doing is Complete C# Unity Game Developer 2D and I am having the issue after following the instructors lesson in course 114. Boundaries.

I followed the code shown and have double checked it. After setting up the min and max bounds to the main camera the ship is bound to the center of the screen and is reset to it after any movement input is made. Commenting this part of the code out allows the ship to move as expected.

I could just make my own colliders to stop the ship leaving the cameras view but this isn’t what’s expected and may cause issues later on in the course.

I’m unsure where I have gone wrong, can anyone help me with this issue?

Thank you.

Hi,

Welcome to our community! :slight_smile:

First of all, good job on analysing the code and narrowing the problem down. Since you figured out that the spaceship moves as expected when its position is not clamped, we know that the problem is very likely caused by the clamp values.

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Maybe there is a typo in one of the lines where we set the min/max values and/or where we use it in the Mathf.Clamp method.

Did this help you find the problem?


See also:

I went through it a couple times checking for spelling mistakes or misplaced capital letters. But I wasn’t able to find anything that was causing the issue. I also made sure the script was attached to the correct objects and they where correctly placed in the scene.

I ended up just starting a new project and for whatever reason now it’s working as intended. I’ve compared the code in both the scripts and I still can’t see why the redone project works and the older doesn’t.

Either way it is working now. Thank you for your time.

I’m glad you solved the problem. :slight_smile:

Next time if something does not work as expected and if you already compared your code but were not able to spot any difference, please share the code as formatted text. Also share screenshots of what you did and have in Unity. In many cases, it’s just a little detail that causes a problem but they are often difficult to see.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms