|
Hello, 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. Cheers
(comments are locked)
|
|
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. Humm, thats still not doing it - its just shooting in the same point no matter what
May 23 '11 at 10:44 PM
oliver-jones
Still not working. Basically - Instead of the raycast just firing forward, I want it to fire forward as well as moving up or down on Y on 'target'.
May 23 '11 at 10:50 PM
oliver-jones
Hm, I'm still not sure I understand your question correctly. Does the player control this up/down movement? Or do you want the ray to always fire straight, but have its height automatically adjusted so that it reaches the target's height if the player is facing the target?
May 23 '11 at 11:08 PM
Wolfram
Your second option - thats exactly what I want 'ray to always fire straight, but have its height automatically adjusted so that it reaches the target's height if the player is facing the target'
May 23 '11 at 11:10 PM
oliver-jones
In that case, your starting point would be transform.position, and your direction is:
May 23 '11 at 11:15 PM
Wolfram
(comments are locked)
|
