Basically, I have a raycast system that shoots out a raycast directly forward. The problem I'm having is that I don't want it to fire directly straight from the transform. I want it to be able to fire at a target but only on the Y axis.
Here is what I'm using:
So now - its firing straight. But I want it to be able to fire straight at a target but be able to move up or down on the Y axis (if the target is higher than the raycast).
Ive tried changing the var direction to:
But it appears to be firing at the same spot no matter what.
Can someone help me out please.
Your direction needs to be a difference between two vectors, not the target position itself. Try this:
As a side note, instead of transform.TransformDirection(Vector3.forward) just use transform.forward.
EDIT: Unless I misinterpreted your question. If you want a ray from your current position to the target's position, simply use target.transform as the starting point, and:
as the direction.