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 3Dmajid2012 · Jul 17, 2012 at 10:07 AM · cameracollisionphysicslinecast

How to use linecast ??

hi my friends. i am working on my simple game. its a ball that have third person shooter camera. i have used Mouse orbit and Smoth Follow scripts. my game works properly but i have a problem with camera. my camera through wall in closed place. i found out that i should use Physics.castline to detect collision between camera and actor (the ball).i wrote this code but its always true ! and never be false.

 void Update()
 {
 
     if (Physics.Linecast(gameObject.transform.position, wall.transform.position))
     {
 
         Debug.Log("collected");
     }
     if (Physics.Linecast(gameObject.transform.position, wall.transform.position)==false)
     {
 
         Debug.Log("not collected");
     }
 
 }
Comment
Add comment · Show 3
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 ScroodgeM · Jul 17, 2012 at 10:29 AM 1
Share

does your wall have a collider? if so, this will always return true cause you always intersect it with this line.

avatar image 3Dmajid2012 · Jul 17, 2012 at 10:59 AM 0
Share

yes my walls have colliders. So how i can to fix my problem ?

avatar image Bunny83 · Jul 17, 2012 at 11:01 AM 0
Share

@3Dmajid2012: If you don't want to answer your own question, don't post answers. I've converted your answer into a comment.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ScroodgeM · Jul 17, 2012 at 11:03 AM

1 make you ball in individual layer

http://docs.unity3d.com/Documentation/ScriptReference/GameObject-layer.html

2 when you need to check the ball by linecast, filter it by ball's layer

http://docs.unity3d.com/Documentation/ScriptReference/Physics.Linecast.html

or, simply add wall to 'ignore raycast' layer if you needn't raycast them at all

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

Camera (mouse orbit), linecast and shakiness 1 Answer

Trying to fix bouncy linecast camera collision 1 Answer

Camera gets flung off of the map when the player collides with certain objects. 0 Answers

Camera Collision Help Thanks In Advance 1 Answer

Addforce to ball in camera position 0 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