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 mrsev · Aug 26, 2017 at 12:47 PM · physicsraycastraycasthitraydrawline

Raycast hit.point differs from Ray direction [SOLVED]

[EDIT] Messed up with Raycast's parameters : for direction I put a position, not a true direction == player.transform.position - eyes.transform.position

Instead of just player.transform.position... Noob mistake //END

Hello everyone,

My enemy shoots a raycast from his eyes to the player's position (cible). It uses a Ray "viseur" (see script).

As you see on the picture, the yellow line, which is the same as the Ray viseur, is correctly oriented to the player.

The cyan line is the hit.point, which is totally abnormally hitting the wall, wrong direction. But the Raycast uses the Ray, so how is that possible??? The enemy is in IgnoreRaycast layer.

I'm lost... Thank you for your help.

                 if (angle < fieldOfView * 0.5f) //angle between enemy and player
                 {
                     Debug.Log("angle is right");
                     RaycastHit hit;
                     Vector3 cible = player.transform.position;
                     cible.y += 2; //adjusting height
                     Ray viseur = new Ray(eyes.position, cible);                  
 
                     if (Physics.Raycast(viseur, out hit, range))
                     {
                         Debug.Log(hit.collider.name);
                         Debug.DrawLine(eyes.position, cible, Color.yellow);
     //this Line is drawn between eyes of enemy and player (cible) position
                         Debug.DrawLine(eyes.position, hit.point, Color.cyan);
     //this line is between eyes of enemy and hitpoint, they should logically be the same
                         Debug.Log("Raycast fired");
                         if (hit.collider.tag == "Player")
                         {
                             Debug.Log("Raycast touched player");
                             
                             inSight = true;
                             chase = true;
                             agent.speed = chaseSpeed;
                         }
                     }
                 }

alt text

raycast-bug.jpg (309.9 kB)
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 mrsev · Aug 26, 2017 at 12:57 PM 0
Share

I've been trying with direct transform.positions, even without passing through the Ray... all the same weird thing happening.

It shoots from the right place but the player position is wrong when it goes through the Raycast function.

And when testing the Ray, it has the correct DrawLine (yellow).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mrsev · Sep 01, 2017 at 08:23 AM

I have part of the answer.

The goddamn mesh I made it with Blender, which goddamn imports it with rotation problem.

So I corrected the rotation putting the mesh as a Child of an EmptyObject.

Now if I Raycast to forward, it goes to the right of the enemy, so there's a bug with relative Player position or what...

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

176 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

Related Questions

RayCast(Ray ray, out RaycastHit hitInfo, float maxDistance, int layerMask) question 0 Answers

How to cast a Ray using local pivot of an object? 1 Answer

Raycast Hit suddently stopped working 0 Answers

Physics Raycast not working 1 Answer

Disable a UI element when ray doesn't hit it anymore. 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