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 /
This question was closed Apr 18, 2015 at 03:05 PM by YoungDeveloper for the following reason:

Comment in existing question.

avatar image
0
Question by Abacab · Apr 18, 2015 at 02:59 PM · c#cameraraycastraycasthit

RE: RaycastHit and camera through walls

Original question

So the camera now reacts to the walls, but when it does, it starts "crawling" down the wall (when I reverse towards it) until it hits the ground and then it moves through the wall.

 void LateUpdate() {
 
 RaycastHit wallHit = new RaycastHit ();
         Ray wallRay = new Ray (camera.transform.position, car.transform.position - camera.transform.position);
         
         if (Physics.Raycast (wallRay, out wallHit, distance)) {
             if (wallHit.collider.tag == "Wall") {
                 camera.transform.position = wallHit.point;
             }
         }
 }

Comment
Add comment · Show 28
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 Glurth · Apr 18, 2015 at 03:16 PM 1
Share

You are currently resetting the position of the camera every LateUpdate that you detect contact with the wall. I suspect you want to add a flag, and use it to only reset the position the FIRST update that you contact the wall. Obviously, reset this flag when contact with the wall is broken.

This reason this is happening is because your "car" transform is below the camera, so the hit-point on the wall is below the camera. It may be coincidentally stopping when it reaches the floor, but I'd bet,it's actually stopping when it reached the car's y position.

Another way to eli$$anonymous$$ate this effect would be to eli$$anonymous$$ate the Y axis when you create your ray. ($$anonymous$$odify a local copy of car's position to be at the same y coordinate as camera's position- so neither one is below the other. Use this modified vector when creating your ray.) Note: Using a horizontal ray like this would allow the camera to pass over walls that are shorter than the camera is high.

avatar image Glurth · Apr 18, 2015 at 03:24 PM 1
Share

@YoungDeveloper, I think this should be a separate question. If he had not included a link to the other question, would you have closed it?

avatar image Glurth · Apr 18, 2015 at 03:40 PM 1
Share

Yes, that's exactly what I was saying, but that's just my opinion. Ok, as you wish.

avatar image Glurth · Apr 18, 2015 at 03:44 PM 1
Share

$$anonymous$$y pleasure. I'll just copy/paste first comment into original Q, so we can continue discussion if needed.

avatar image Glurth · Apr 20, 2015 at 11:06 PM 1
Share

This logic doesn't seem to actually do anything different.

True, you are using a flag now to hold the boolean hit-result, but you are still updating the position every Fixed update that the camera is touching the wall.

Try na$$anonymous$$g your flag "hadContactLastUpdateFlag". That descriptive name should you help you figure out how to setup the logic. (you are CLOSE)

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

19 People are following this question.

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

Related Questions

Raycast hitting objects to the left of my player 1 Answer

c# editing gameobject returned by a raycast 2 Answers

Camera rotate to look at GameObject from Raycast 3 Answers

RaycastHit: What is the difference between hit.transform.tag and hit.collider.tag, and which should I use when? 1 Answer

I'm trying to get a Raycast Laser weapon to tell whatever it hits to do damage, and its not working. im kindof a noob... 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