- Home /
Raycast to OVRplayercontroller,Raycast to OVRplayercontroller - bugged
Hello!
For some reason when my enemies are casting a raycast towards my player (to determine if the player are within their sight or not) the ray goes towards the player but way below the OVRPlayerControllers y-position and instead goes through the ground. Is there something wrong with my raycast code or is there something wrong with my unity project which causes this to happen? I have been stuck for days now and would really accept all of your thoughts.
When I use Gizmo.DrawRay the ray is perfectly straight towards the OVRPlayerController.
I have also tried LineCast, but the same issue remains.
Any ideas?
Code of my Debug.DrawRay:
Debug.DrawRay(transform.position , (player.position - transform.position ) * range, Color.yellow);
Code of my Gizmo which acts like it should:
Gizmos.color = Color.cyan;
Gizmos.DrawRay(transform.position, (player.position - transform.position) * range);
Code of my ordinary raycast which is strange:
RaycastHit hitInfo;
If(Physics.Raycast(transform.position, player.position - transform.position, out hitInfo, range) {
// check wether or not the hit collider is a player etcetc
}
Unity Version: 2019.3
UPDATE: It seems as if the OVRPlayerController's y-position somehow gets messed up in the update method of the enemy, while in the OnDrawGizmos method within the same enemy the OVRPlayerController's y-position is as expected and is working. I am now the definition of confused and accepts all tips or tricks gladly.. lol.
Answer by korvansvarig · Feb 01, 2020 at 10:52 AM
Found a solution, I had to add a collider to the OVRPlayerController directly and set gravity and kinematic to true in its rigidbody.
Your answer
Follow this Question
Related Questions
Raycast Not Drawing In Target Direction? 0 Answers
Enemy line of sight 1 Answer
Player Raycast Does Not Compute 0 Answers
Raycast target sight? 0 Answers
Can someone help me to understand why this raycast is not working properly? 1 Answer