Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Razputin · May 14, 2018 at 11:26 PM · rigidbodyraycastcoroutine

Why isn't raycast hitting when going left.

My right raycast works fine but the left one never hits anything and It's starting to get frustrating. What am I missing here? The right and left one are identical aside from the direction of the vector3 and the dir. distToSide = GetComponent().bounds.extents.x;

             case EnemyType.Jump:
                 if (!myHealth.invulnerable)
                 {
                  if (dir == 1)
                     {
                         Debug.DrawRay(new Vector3(transform.position.x, transform.position.y, transform.position.z), Vector3.right, Color.green);
                         if (Physics.Raycast(transform.position, Vector3.right, distToSide * dir, ignoreLayers))
                         {
                             if (!waitingToFlip)
                             {
                                 StartCoroutine("WaitToFlip");
                             }
                         }
                         if (!jumping)
                         {
                             rB.AddForce(new Vector3(dir * 225, 300, 0));
                             jumping = true;
                             StartCoroutine("Cooldown");
                         }
                     }
                     else
                     {
                         Debug.DrawRay(transform.position, Vector3.left, Color.green);
                         if (Physics.Raycast(transform.position, Vector3.left, distToSide * dir, ignoreLayers))
                         {
                             if (!waitingToFlip)
                             {
                                 StartCoroutine("WaitToFlip");
                             }
                         }
                         if (!jumping)
                         {
                             rB.AddForce(new Vector3(dir * 225, 300, 0));
                             jumping = true;
                             StartCoroutine("Cooldown");
                         }
                     }
                 }
                 return;
         }
     }
 
     private IEnumerator WaitToFlip()
     {
         waitingToFlip = true;
         yield return new WaitForSeconds(.1f);
         dir *= -1;
         waitingToFlip = false;
     }
 
     private IEnumerator Cooldown()
     {
         yield return new WaitForSeconds(.5f);
         yield return new WaitUntil(() => IsGrounded() == true);
         rB.angularVelocity = Vector3.zero;
         rB.velocity = Vector3.zero;
         jumping = false;
     }
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 iJuan · May 15, 2018 at 01:49 AM 0
Share

distToSide should always be positive (you can't be -5m away from a wall, same as something can't weight -30lbs).

Could you add a Debug right after the left Raycast check? Is the rat being drawn in the proper direction?

2 Replies

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

Answer by bobisgod234 · May 15, 2018 at 01:28 AM

Is "dir" expected to be -1 when moving left? If so, then you multiply "distToSide" by a negative number, which is probably not what you intended.

Try replacing "distToSide * dir" with just "distToSide"

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 Razputin · May 15, 2018 at 01:39 AM 0
Share

Don't I want disToSide to be negtive so that it goes left or no. Also removing it didn't change anything.

avatar image Razputin · May 15, 2018 at 01:56 AM 0
Share

Actually it turns out you are correct. I had accidentally changed the second raycast to be right also while experimenting for a solution. $$anonymous$$ake it an answer so I can accept, thank you!

avatar image
0

Answer by plindsey · May 15, 2018 at 02:11 AM

You want the world left or the objects left? If you want the objects left there is no transform.left you need to use transform.right *-1

For world left maybe try Vector3.right * -1 instead

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

145 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

Related Questions

'height' is not a member of 'UnityEngine.Collider'. 1 Answer

How should I make a custom suspension system? 1 Answer

Touching Falling Objects 1 Answer

Creating a teleportation gun 1 Answer

hit.gameObject.AddComponent not working 1 Answer


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