Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by mauri11 · Feb 25, 2015 at 08:44 AM · raycasting

transform.TransformDirection setting a size?

I am shooting raycasts and was wondering if there is a way to set a size for the raycast? Right now its shooting forever until it hits something. Im trying to set a specific length or size to the raycast.

 RaycastHit hitInfo;
 Vector3[] direction = new Vector3[5];//Array of Raycasts 
 
 void Raycasting(){

 this.direction[0] = transform.TransformDirection (new Vector3(-1f,0f,3))*3;
 this.direction[1] = transform.TransformDirection (new Vector3(-.5f,0f,3))*3;
 this.direction[2] = transform.TransformDirection (new Vector3(0f,0f,3))*3;
 this.direction[3] = transform.TransformDirection (new Vector3(.5f,0f,3))*3;
 this.direction[4] = transform.TransformDirection (new Vector3(1f,0f,3))*3;
 
 }



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 HarshadK · Feb 25, 2015 at 08:45 AM 1
Share

If you look at the documentation for the Physics.Raycast there is an argument for theRaycast called 'distance' which is what you need.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by PokeJoe · Feb 25, 2015 at 09:50 AM

http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

The third parameter of the Physics.Raycast() function is the distance, which should be given as a float. By the way, what you have is not an array of Raycasts, but an array of Vector3s, which are only one component necessary to do a Raycast (which is a function, something you do, not an object, something you have).

So when you call the function later on, make sure you specify the distance.

Comment
Add comment · Show 1 · 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 mauri11 · Feb 25, 2015 at 06:46 PM 0
Share

Thanks a bunch that helped me clear things up. Works great now. Here's my code that I did to fix it. Hopefully it will help someone. It's in a for loop.

Physics.Raycast(transform.position, this.direction[i],out hitInfo, 10.0f)

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Click Point From Raycasting Not Yielding Expected Coordinates 1 Answer

SInce when?!?!? (Raycast issue) 2 Answers

Checking the position of the mouse cursor in 3d space 2 Answers

How to detect certain object using raycast 2 Answers

Having problems changing the material of current target. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges