Hello,
I was having trouble with my InteractWithCombat() Method, specifically on the Raycast detection.
I initially tried multiple fixes to no avail:
- Ensuring the right scripts are attached to the enemy, the code is proper and the box collider is accurately placed on the enemy mesh. Ensured that Debug.DrawRay was on and that I was actually hitting the box collider.
- Turning off Queries Start In Colliders in Edit>ProjectSettings>Physics2D .
- Screen size was consistent and set at the same size for both Debug and Release Mode (16:9).
Here’s where it gets interesting. After hours of tinkering and debug statements everywhere, I found out that there are two things make the detection work again:
- When I am in Release Mode, I would have to fire UNDER the enemy box collider to trigger the InteractWithCombat() Method, whereas in Debug Mode I could just click at the box collider and everything works out nice.
- When I check off “Use Gravity” in my enemy’s rigidbody component (see below), suddenly the detection works well even in Release Mode. Please note that I DO have a box collider on my ground.
The only things that are different from the lectures is that I am using CinemachineVirtualCamera with a Cinemachine Collider Script instead of the camera used in the lectures, and that my enemy has a rigidbody. I can honestly move forward by just removing the rigidbody on the enemy, but I was interested in potential reasons on why the code wasn’t working as intended, and to see if anyone had any insight on this matter. Thank you.