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 /
  • Help Room /
avatar image
0
Question by MomkeyDev · Nov 03, 2020 at 04:03 PM · nullreferenceexceptionraycastingraycasthit2d

Raycast2D hit.point is zero ?

So what im trying to do is making my character climb a ledge, but when trying to make a logic where i put my player snap to near the ledge/wall. the hit.point keep returning zero. i do found that the hit.collider return null, thought it did hit something and i don't know why hit.point is zero. any answer will be really appreciated

 //what im trying to do in this script is basically snapping my player near the ledge
 //when they want to climb, but the hit.point only return zero vector
 
 float LedgeRayDistance = 1f; //The Distance for ray
 
 bool LGU;               //BOOL TO CHECK THE TOP OF PLAYER
 bool LGM;               //BOOL TO CHECK THE MIDDLE PART
 bool LGD;               //BOOL TO CHECK THE BOTTOM PART
 
 Vector2 LRay2;          //The offset for the bottom ray
 Vector2 LRay3;          //The offset for the middle ray (Sorry for weird numbering)
 
 LayerMask WhatIsLedge;  //The layer mask to seperate the player at first
 
 //what this if basically do is to check if both the LGM and LGD is true and LGU is false
 //which basically mean they can climb
 if (!LedgeCheckUp && LedgeCheckDown | LedgeCheckMiddle)
 {
     //Change the transform to near the ledge
     if (LedgeCheckDown)             //If it's on the bottom part that got true
     {
         //this next logic basically calculate the distance between the hit.point and
         //the player position + player collider size in the x (so it doesn't overlap)
 
         Vector2 Ledge2 = (Vector2)transform.position + LRay2;       //calculate the 
         RaycastHit2D hit = Physics2D.Raycast(Ledge2, Vector2.right * transform.localScale.x, LedgeRayDistance);
                 
         //Where the problem start, i don't know why but the hit.point is returning zero
         Vector2 Ledgepos = hit.point - (Vector2.right * GetComponent<BoxCollider2D>().size.x * transform.localScale.x);
         transform.position = Ledgepos;
     }
     else if (LedgeCheckMiddle)      //if the middle part that got true
     {
         //The same as above. not really important
 
         Vector2 Ledge3 = (Vector2)transform.position + LedgeRay3;
         RaycastHit2D hit = Physics2D.Raycast(Ledge3, Vector2.right * transform.localScale.x);
         Vector2 Ledgepos = hit.point - (Vector2.right * GetComponent<BoxCollider2D>().size.x * transform.localScale.x);
         transform.position = Ledgepos;
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

219 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

Related Questions

Select from multiple character to move 0 Answers

NullReferenceException on Raycast 0 Answers

Why this if logic isnot short circuiting? 0 Answers

Rigidbody blocking raycasts 2D 0 Answers

Is there any way how to do raycasts like this? 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