- Home /
DrawRay not drawing a ray
Hi,
When my character lands on a bomb trap I want a ray to be cast to assess the objects around the character which will determine how and where he is flung. I am trying to use Debug.DrawRay in order to make sure I'm casting the ray correctly, but nothing appears to be happening. I'm not getting any errors.
When my character lands on the bomb trap the following function is triggered. The Vector3 "bombForceDir" is a random direction determined in another function. For the sake of this example lets assume its (1,0,0).
public void PlayerExpload (Vector3 bombForceDir)
{
if (Physics.Raycast (transform.position, bombForceDir, 2))
{
Debug.DrawRay (transform.position, bombForceDir, Color.green, 5);
}
}
Thank you for any help!
Answer by Jwizard93 · Jul 05, 2017 at 11:31 PM
This will draw in the scene view tab only. Or you can enable gizmo drawing in the game view to see it there too. There's a little gizmos button at the top of the game view. This is in the scripting API documentation.
Thank you for the help! I wonder if you could answer another related question for me. The script that contains the code above is on the player which is not at (0,0,0), but for some reason within this particular function the "transform.position" reference is acting as if it is and when I do "print(transform.position);" it tells me (0,0,0). Everywhere else in this script it gives the position correctly, but not here. Any idea why?
Thank you again!
No that is strange. Very curious. transform.position should always be the attached object's position in world space I believe.
Are you sure that function is within a class derived from $$anonymous$$onoBehavior and attached to the player?