- Home /
Question by
jimmyismike · Aug 04, 2012 at 01:13 AM ·
raycastshootingtutorialnew
Raycast Shooting Help
Can someone here give me a link to a tutorial on shooting with raycasts? I don't want wanna script from anyone unless its bare to the bones. I don't know to much about raycasts if anyone can point to a video tutorial or somewhere helpful in unity documentation that would be great. Thank you -jimmyismike
Comment
Best Answer
Answer by speedything · Aug 04, 2012 at 01:50 AM
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
Think of it this way...
var hit : RaycastHit // This will store the thing we hit with our Raycast
if(Physics.Raycast // If we hit something
(transform.position, // Start the ray from this transform's position
transform.forward, // Fire it forward
hit, // Save the thing we hit in the the variable we created
100) // This is the length of the ray we fire
If the ray we fire hits something then we now have the RaycastHit variable hit. We can now use this to access the object.
hit.collider.transform // This is the transform of the object we hit. Do with this as you will!
This definitely explains it better than most of the other posts I've looked at have said. Thanks :D