Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Spectrum_Studios · Jun 23, 2018 at 04:42 PM · collisionraycastlinecastfast

Raycast not consistently detecting collision.

In my game, I have a ball that bounces around as it hits stuff it gets continuously faster. First I had walls around my ball to keep it in and I was using raycasting to detect whether or not it was within the walls. That worked decently, but the problem was that after the ball got fast it sometimes would shoot through the wall and was gone from the screen. I decided to change how I keep my ball on the screen by calculating the height and width of the screen and making sure the ball doesn't leave that location. However, when I did this, it broke the other raycasting that I was doing. There are some objects that the ball needs to collide with still. What is weird is that sometimes it detects the collision, but sometimes it doesn't. At first, I didn't change the raycast at all, but I tried fixing it using a single linecast. This does the same thing as the raycastall. it sometimes detects the collision, other times it doesn't. Here is my code for the ball.

     private void Awake()
     {
         this.speedAmountX = Random.Range(-14f, -8f);
         this.speedAmountY = Random.Range(-6f, 6);
     }
     void Start () {
         this.mPrevPosition = transform.position;
         this.numOfPaddleHits = 0;
         this.restart();
 
         
     }
     
     // Update is called once per frame
     void Update () {
 
         this.mPrevPosition = transform.position;
         this.advance();
         this.OnRayCastHit();
 
     }
     public void advance()
     {
         this.transform.Translate((this.speedAmountX * Time.deltaTime), (this.speedAmountY * Time.deltaTime), 0f, Space.World);
     }
 
 
     private void OnRayCastHit()
     {
         RaycastHit hitInfo;
         if (Physics.Linecast(this.mPrevPosition, this.transform.position, out hitInfo))
         {
             if (hitInfo.rigidbody.gameObject.name == "Paddle" && this.speedAmountX < 0)
             {
                 this.numOfPaddleHits += 1;
                 this.bounceHorizontal();
             }
             if (hitInfo.rigidbody.tag == "Sqaure")
             {
                 hitInfo.collider.gameObject.GetComponent<Square>().restart();
                 this.bounceHorizontal();
             }
         }
     }

 

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

1 Reply

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

Answer by Spectrum_Studios · Jun 23, 2018 at 05:37 PM

I found my issue. I was calling the advance to the ball in multiple locations, so it through off where the casting should be.

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

221 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 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 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 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 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 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 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 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 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 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 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 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

Restrict held object movement 0 Answers

Detecting whether hit point was left or right of the center of rotating box collider 1 Answer

Merge two gameobjects and create a new one unity2D! 0 Answers

Rotated object raycasting in wrong directions!!? 3 Answers

About Camera Collision 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