|
What I am trying to achieve:
If I need to shoot say 3 raycasts (C#): 1 from transform.position (blue line), 1 to the left of this by an offset of lets say 2 units (left yellow line), and 1 to the right by the same offset (right yellow line), how can I do this? I imagine it could be something like: transform.position + publicVariable (and) transform.position - publicVariable Here is my script: public float rightRaycast = -2f; What is the best way to do this?
(comments are locked)
|
Thanks for your help. I threw in a diagram up top to better show what I'm trying to do. The blue line is the first raycast (mytransform.position) in the script and the left yellow line is the left raycast (myTransform.position, myTransform.right * leftRaycast). I've changed the second raycast to as you suggested but it changes the angle of the raycast it doesn't actually offset it. Or have I done it wrong?
Mar 07 '12 at 09:49 AM
Hamesh81
Keep in mind that a ray is composed of two things, an origin and a direction. Saying "the first raycast (mytransform.position)" makes no sens if you don't add the direction (I suppose you imply it's forward there). So you want to cast a ray forward, to the right and to the left, with an offset on the origine : the the three lines of codes in my answer. the direction don't need to be multiplied, unless you want to invert it. In your case, and respectively with the origines I gave you, directions are transform.left, transform.forward and transform.right.
Mar 07 '12 at 03:36 PM
Berenger
Thanks for trying to help Berenger, but I couldn't get your solution to work. I ended up using a Vector3 variable to determine the direction which allowed me to set a ".x" offset for the other raycasts. All is gd now :D
Mar 09 '12 at 03:22 PM
Hamesh81
(comments are locked)
|

