Transform.LookAt() not accurate?

Hi,
Been having problems with getting a projectile to fire at a specific location so I did a test with primitives:

CreateEntity()
{
 //Create an CUBE at the Heading (a Vector3)
                GameObject g = GameObject.CreatePrimitive(PrimitiveType.Cube);
                g.transform.position = i_rcParams.Heading;
               

//create an Cylinder based on the forward transform of an object with "Look at"
               //create an object to act as a "ray"
GameObject c = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                GameObject ray = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                ray.transform.position = rcEntity.Transform.position;

//now make the ray look at the heading.
                ray.transform.LookAt(i_rcParams.Heading);
//set position of cylinder along the ray forward transform.
                c.transform.position = ray.transform.forward * Vector3.Distance(i_rcParams.Heading,ray.transform.position);

}

Am I crazy or should the Cube and Cylinder objects be positioned at the same location? They are not even close. What is more strange, the more I move the rcEntity from the origin of the scene the farther apart the cyllinder and cube objects get created. (The capsule is getting positioned at the rcEntity regardless of location as expected.)

The answer to every “am I crazy or is [basic math function which has been around for 10 years and if it was somehow ‘not accurate’ nobody’s code could ever work] not working?” question is yes, you are crazy. :wink: This code makes no sense:

c.transform.position= ray.transform.forward*Vector3.Distance(i_rcParams.Heading,ray.transform.position);

Presumably you mean:

c.transform.position= ray.transform.position + ray.transform.forward*Vector3.Distance(i_rcParams.Heading,ray.transform.position);

–Eric

Thanks you lol. Note to self, when trying to track down a nasty bug at 2:00am. Stop and look it in the morning :wink: