[SOLVED ]Royal Run ~ Level Generator Script ~ Unity Physics Engine Issue

Hi! I am Ahmed! Currently, I watching the unity game dev course which has multiple games. I am making Royal Run but I am stuck at a point where I can’t continue my course without solving! I am facing issues with unity physics engine! The obstacles in my game are moving in the same direction as mine whenever I collide with the fences or an obstacle. The obstacles are also jumping anonymously when they collide with the fences. My course instructor is Stephan Hubbard, he’s a great guy. I am pasting some photos of code. Please reply as soon as possible!


I am facing issues with this method only! The code below the comments is the previous code and the commented code is the new code but both have same the issues!

Hi Ahmed,

Welcome to our community! :slight_smile:

I’m not sure if I understood this problem because this behaviour sounds correct to me. The fence has got a collider, and if another collider collides with it, the physics simulation makes the collider bounce off.

Maybe comment the changeChunkMoveSpeed() method call out. Then test your game again to see if this code causes the problem. If the problem disappears if you don’t call changeChunkMoveSpeed(), the problem is indeed inside this method. If it does not disappear, the problem is very likely somewhere else.

Could you perhaps upload a video of the problem to Youtube, and share a link here? That would help me understand the problem better.

Yes, I will!

Here is the link to the video.

Thank you. That was helpful. This looks as if there might be another collider in the scene. Maybe a big invisible collider pushing the obstacles forwards. Please check all game objects in your Hiearchy including the camera game object. The camera must not have any collider attached.

Thanks for the response, I really appreciate your help but there is no collider in my scene and by any chance if there is any collider then why the objects didn’t resist first when I played the game before hitting an obstacle or picking an apple. The problem is with ChangeChunkSpeed() mehtod or the the physics settings!

Hi Nina!

So did you get a glimpse on what is happening with my objects? Could you please reply me as soon as possible! If possible then please share this problem with Stephan, I think he will understand this problem!

We TA usually do not work at the weekends. If you need faster help, please feel free to ask our helpful community of students over on our Discord chat server.

Unfortunately, I don’t know what else could be causing this problem in your game. Could you please fill out our form and send me your zipped project (without the Temp and Library folders)? Please don’t forget to add a link to this thread. When you are done, drop me a line here, so I can check our server.

I have filled the form and uploaded the file.

Thank you. I’ve just downloaded and tested your game. You are right. The problem is indeed in the ChangeChunkMoveSpeed() method.

When I tested the game, I suspected that the z-gravity might be positive but the value in the Physics Settings is negative. However, when I logged newGravityZ into the console while playing the game, that value suddenly became positive.

I then checked the LevelGenerator component in the Inspector and noticed that both the minGravityZ and the maxGravityZ values were set to 2. Setting those values to a negative value solved the problem for me.


See also: