I am making an Asteroids clone and I have kind of a complicated situation to describe but really I have narrowed the core problem to a single line of code in my script:
meshCollider.isTrigger = false;
where meshCollider is an object of type MeshCollider which I have passed into the script (kinda obvious)
I am calling this code when the ship in my game crashes into an asteroid and my ship waits 3 seconds to respawn - while it is waiting those 3 seconds I set the collider to non trigger so it doesnât keep crashing into asteroids while itâs not âaliveâ
The âproblemâ itself is a bit hard to explain, but the main gist of it is that line of code seems to be affecting the collider of another totally unrelated GameObject in my game. Before my ship ever dies the other GameObject works fine. Once my ship has died once then it breaks.
The STRANGE thing is if I comment out the line and âmanuallyâ do this - as in, when my ship collides with an asteroid (The ship âdiesâ and needs to wait 3secs to respawn) I just pause the game (or not), untick Is Trigger, and then when my ship spawns back, i re-tick it, and the problem does not happen
I have been trying to figure this out for hours and Iâve run out of things to try, at this point I could swear itâs a unity bug, so if anyoneâs got any suggestions Iâd much appreciate it
Double check that your meshCollider variable is properly set.
You can use Debug.Log(â!â, meshCollider.gameObject); and it will send an arrow to the GameObject that owns the meshCollider when you click on the Debug error.
Other than that, did you set ignore collision to the meshCollider and other object? Or did isolate the part that screws up on the other object?
While meshcollider does inherit from collider, I would recommend just casting it as a collider (and making your variable of type Collider) instead. Youâll probably have less issues.
Doesnât seem to indicate anything about the gameobject owner?
**Edit:**Oops, right, I see, it highlights the gameobject which the script belongs to, and yeah, itâs the right one
Well there is only one MeshCollider in my entire scene so there is not really any possibility that the line affected any other objects. (And yea, meshCollider is definitely of type MeshCollider)