Raycasting issue for maximised screen

Hi All,

I have 2 game objects. One is a character model and the other is just an object about half the height of the character. I have game and scene views on my computer screen at the same time. When playing in such a layout, my raycasting works fine but whenever I maximise my screen, the raycasting is unable to detect the object in front of my character. Why is this so? Is there some issue with my origin parameters?

Exactly the same code I used for my testing as shown below. Theoretically-wise, what went wrong? Both have colliders and my character is able to knock against it. One weird thing I notice is when I maximise the “play” mode, the object seems to be 1/3 the height of my character instead of 1/2. Thanks.

if(Physics.Raycast(thePlayer.transform.position, thePlayer.transform.TransformDirection(Vector3.forward), out hit, 3)) Debug.Log(“ok”);

2 Answers

2

Check the z position of your character.

Try to place them far away from each other and check if the raycast is hitting.

thanks ahaykal!

–

Answering my question for the benefits of others. If using a smaller screen when in play mode works but not when it is maximised, do extend the bottom side of the collider of the object.

You may use debug.drawray or debug.drawline to check the rays. Remember to turn on your gizmos.

I have never expected when both my character and the object which start at the same Y values, when maximised, there is a slight offset on the object. It is slightly higher. Thus, the rays emaciating from the player are unable to hit on the object.

Funny issue, could be my problem, but just extending the bottom collider will simply solve it.