I recently updated a project and now parts of my game do not work correctly and there’s no errors or explanation, I’m using 6000.0.22f1 as of right now and the project I updated seemed fine, all seemed to work well until I noticed a strange glitch.
My project is a space shooter, turrets in game fire towards the player, but now for the most part they ignore the player and fire off randomly into space, no explanation as to why, no error messages or warnings in my project, it all looked great until I noticed that oddity.
Any advice would be a boon, thanks
Well you know what isn’t working, now it’s up to you to debug why it isn’t working. I would probably investigate how they get the player position first and see what is falling over there.
Thanks for your reply, well the code is the same, just the actions are different, I’m just completely lost, I could fettle the code, but as it was working perfectly before the update and it’s not showing any errors, I’ll need some extra help.
So, my player when near a turret will be fired upon until the player moves past it or destroys it, what happens now is the player is found but the bullets fire towards the middle of the screen (but not all the time which makes this weird) I don’t know if it’s this code, which handles turret fire or the way a bullet is propelled or what, what’s the best way to debug this when, I’ve not done it right before, I just coded it all up to work now for some reason it’s not doing what it used to do.
Anyway, the turret fire code is below, I changed a few depreciated code lines Unity was asking me to change which I did, but it’s still the same.
Anyway, any help would be a boon
Well you didn’t say what version you updated from, but depending on the number of major or minor versions updated from, any number of things can change. Its also possible to have something work one day, and not work the next, potentially due to things like non-deterministic order of execution.
And if it only - as you say - works ocaisionally, it could’ve been it never worked properly in the first place, and you’re only noticing these issues now.
If the issue is the turrets not aiming correctly, then you have a point to focus on. Focus on the code that calculates the directions/rotations, log their values, and try to come to understand why they might be getting the desired result. Use the managed debugger if necessary: Unity - Manual: Debug C# code in Unity
There are some things in your code I can see that don’t make sense. Like on line 60 you’re comparing the distance between two directional vectors, which makes no sense. Vector3.Distance is meant for two positional Vector3 values. Comparing two directions is likely to not get the desired result.
Lerping with t as Time.time is also not really going to do what you expect. Lerp expects a value from 0 to 1, so Time.time is always going to give you the end value.
Try to avoid using euler angles as well, as they often do not give the desired result. One set of euler angles can represent multiple different rotations. This is why Unity uses quaternions to avoid this issue.
I don’t mean to nitpick, but there is a lot of things going on making this code much harder to parse than it needs to be. Most if not all of your GetComponent<T> calls could just be assigned via the inspector instead. You’re using FixedUpdate() for something that is not using physics, so should be in Update() instead, and the turret firing really doesn’t need to be a coroutine. Again, don’t mean to nitpick, but one way to avoid bugs is to write code in ways that is easier to parse.
1 Like
Thanks so much for your incisive reply, I’ll be back hopefully once I’ve improved upon things here and found a solution to my particular problem, but you’ve given me food for thought.