- Home /
Unity C# - RaycastHit internal error?
this is my code
RaycastHit hit = new RaycastHit();
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit)){
distance = hit.distance;
}
these are my errors
"Unexpected symbol "
"Parsing error"
I don't get it, the code looks right, can some one please tell me what I am doing wrong?
Answer by Nabeel Akhtar · Aug 07, 2015 at 09:18 AM
There is no function of Raycast with these parameter. You should select one from given types Look at them here http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
Well example for you is float deplovementheight = 1f;
RaycastHit hit; Ray ray = new Ray(transform.position,Vector3.Forward);
Debug.DrawRay(transform.position,Vector3.Forward*deplovementheight); // This will for debuging in will show the ray in playmode
if( Physics.Raycast(ray, out hit,deplovementheight)){
//DO YOU WORK HERE
}
Not sure if this is the code problem or nor, but the raycat seems to be going down and jumping up to the top again
It doesnt do that as it will be pointing to positive z-axis in world coordinates. Well try using transform.forward ins$$anonymous$$d of Vector3.Forward in ray and debug. Hope you will get an idea. This will in in object local coordinates
Your answer
Follow this Question
Related Questions
Getting camera to not see under the ground 3 Answers
How to raycast camera 3rd Person? 0 Answers
Start raycast from object 1 Answer
3rd person camera reset bug 0 Answers
get the point where the raycast hits the world groud? 1 Answer