- Home /
RayCastHit
Hello,
I have 1 problem with raycast.
Code:
#pragma strict
var dot : Transform;
var defDotPos : Vector3 = Vector3(0, 1000, 0);
function Update()
{
var ray = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if (Physics.Raycast(transform.position , ray , hit, 150))
{
dot.position = hit.point;
}
else
{
dot.position = defDotPos;
}
}
This script is supposed to show a point(sphere) on the object which is in front of the character, but actually it loops sphere between character and that object. here is picture so you can see http://prntscr.com/1g70d7
Its sidescroller im talking about.
There is nothing wrong with that code. It's probably something else thats setting the position.
It is possible you are hitting a collider you do not expect. Put this on line 12:
Debug.Log(hit.name+","+hit.tag);
Answer by RyanZimmerman87 · Jul 18, 2013 at 11:46 PM
Really hard to tell what exactly you're trying to do the code is a bit vague. But my best guess is you have some kind of collider intercepting your ray cast before it's expected collision. Most likely the character object if the ray is being cast from inside the character.
Set a layer for your character and ignore that layer in the raycast.
Your answer
Follow this Question
Related Questions
list.contains isn`t working 1 Answer
My grid is getting created on the wonk 1 Answer
Hazards not Working Properly 1 Answer
Setting the position of an object which checked the position under with raycast 0 Answers
Animations - Cycle Offset 2 Answers