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 /
avatar image
0
Question by superlevani · Jan 15, 2014 at 03:04 PM · rotationpositionmathmathfintersection

Find intersection (with Picture)

it's a math question. i couldn't form it as text, so i made a picture

alt text

ques.png (77.4 kB)
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

2 Replies

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

Answer by nesis · Jan 15, 2014 at 03:13 PM

If the black line is pointing the same direction that the player is facing, you can make a script and attach it to the player's GameObject, and in that script, you can use transform.forward to get the direction the player is facing.

In the C# code, you'd write it as:

 Ray ray = new Ray(transform.position,transform.forward);
 RaycastHit hit;
 if (Physics.Raycast(ray,out hit,Mathf.Infinity)) {
     //if an object with a collider was hit by the ray, Physics.Raycast() will return true

     //the "hit" variable now contains information about what 
     //the raycast intersected with first - look at the 
     //documentation for Physics.Raycast for more info:
     //http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
  }
Comment
Add comment · Show 1 · 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 superlevani · Jan 15, 2014 at 03:31 PM 0
Share

thanks, i chose RaycastHit.point and it works fantastically

avatar image
0

Answer by timcommandeur · Jan 15, 2014 at 03:18 PM

This might be a hacky solution. But I would use raycasting with a ray thats bellow the player and parallel to the players rotation. Then change the position.y of the hit info to the max bound y of the cube. The ray in this case would start inside the cube the player's standing on so I'm not sure if it will think it's colliding with the current cube the players on. To solve this you could use raycastall and ignore the first hit. Hope this helps.

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 nesis · Jan 15, 2014 at 03:25 PM 0
Share

Unity works with convex colliders, it only checks if you're going from outside to inside a collider. This means that if a raycast starts inside a box collider, there's no way you'll get a collision with that same box.

superlevani, it'd be good if you could clear up what exactly you're wanting, even if you're unsure of the ter$$anonymous$$ology. On closer inspection, it seems like you're wanting the black line to be following the same horizontal forward direction of the player, but rotated so it sits exactly on the top edge of the cube?

avatar image superlevani · Jan 15, 2014 at 03:32 PM 0
Share

thanks for answer, but nesis's answer was better, so i chose it as accepted

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

20 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

Related Questions

Positions to rotations of a regular GO 2 Answers

Calcultate spawn position based on spawn volume's rotation 2 Answers

Making an enemy face the Player 0 Answers

Rotate Center Pivot based Object like a Draw Bridge 2 Answers

Mathf.Lerp not working 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