- Home /
Question by
$$anonymous$$ · Jul 31, 2013 at 03:33 AM ·
positiondebugdebug.drawline
Raycast and Debug Line Position
help please -???-
I've tried to add an empty object for new transform, but did not work.
tak berjudul.png
(367.6 kB)
Comment
Best Answer
Answer by aldonaletto · Jul 31, 2013 at 03:46 AM
If you child an empty game object to the character at the desired position, this will work - but you must set the raycast origin at this object! Supposing that the empty object is named "Head":
private var head: Transform;
function Start(){
head = transform.Find("Head"); // get a reference to "Head"
}
The raycast may be done like this:
// cast a ray from head.position in the parent's forward direction:
if (Physics.Raycast(head.position, transform.forward, hit){
// something was hit
}
Another possibility is to define the offset in a float variable:
var offset: Vector3 = Vector3(0, 0.9, 0); // offset from transform.position
Do the raycast like this:
if (Physics.Raycast(transform.position + offset, transform.forward, hit)){
...