• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
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
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jimmyismike · Aug 04, 2012 at 01:43 AM 0
Share

Can anyone out there help out?

1 Reply

· Add your reply
  • Sort: 
avatar image
4
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!
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jimmyismike · Aug 04, 2012 at 06:34 AM 0
Share

Thank you that helps.

avatar image Armoth288 · Jun 29, 2014 at 11:16 PM 0
Share

This definitely explains it better than most of the other posts I've looked at have said. Thanks :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

FPS shooting 1 Answer

problem with scripting 1 Answer

Really want to get into Unity but dont understand coding 1 Answer

Raycast shooting 3 Answers

Problem in Shooting Accuracy 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges