RayCastHit help

Hello,

I have 1 problem with raycast.

#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 Screenshot by Lightshot

Its sidescroller im talking about.

I’m not sure what’s going on with that transformdirection function, but one way to do what you want is to simply call the raycast like this:

Physics.Raycast(transform.position , transform.forward, hit, 150)

Let me know if that doesn’t help.

It creates a sphere where it hit
then the raycast hits the sphere in its new position, so moves it closer to the the player
then the raycast hits the sphere in its new position, so moves it closer to the the player
then the raycast hits the sphere in its new position, so moves it closer to the the player
then the raycast hits the sphere in its new position, so moves it closer to the the player
etc
Remove the collider from the sphere

hpjohn ty so much bro. ur king!