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 Xeon-13 · Mar 16, 2018 at 05:59 PM · navmeshpositioningedgecorner

Push object away from edge/corner

I'm trying to place portals to the mouse click positions. How do I make sure that portal completely overlaps underlying plane when user clicks too close to the edge or corner? Here is an example.

alt text

The only solution I can think of is create another collider mesh (similar to nav mesh) where each wall or floor is shrunk (colored with blue on picture). And when user clicks on real wall, find nearest point on shrunk mesh and place portal there. But then I have to create manually "nav mash". Is there easier way to place portal correctly?

Find nearest point from MeshCollider work only with convex. But in my case its just multiple planes separated from each other. So I'll have to manually iterate through triangles to find nearest point.

Any other suggestions would be greatly appreciated. :)

po.png (134.7 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 Xeon-13 · Mar 20, 2018 at 07:16 AM

I think I found a solution using RayCast + SphereCast.

  1. RayCast mouse click to find hit with wall

  2. SphereCast from above that hit point to find hit with "nav mesh"

  3. Use point from 2nd hit and normal from 1st hit to place a portal

          Ray ray = Camera.main.ScreenPointToRay(click);
             RaycastHit rayHit;
             if (Physics.Raycast(ray, out rayHit, Mathf.Infinity, NOT_NAV_MESH_MASK))
             {
                 RaycastHit sphereHit;
                 if (Physics.SphereCast(rayHit.point + 1.001f * rayHit.normal, 1f, -rayHit.normal, out sphereHit, Mathf.Infinity, NAV_MESH_MASK))
                 {
                     OpenPortal(sphereHit.point, rayHit.normal);
                 }
             }
    
    

Here is port mesh drawn with green lines.

alt text


port-mesh.jpg (201.3 kB)
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
avatar image
0

Answer by DarkToadster · Mar 17, 2018 at 06:33 AM

Hey there ! I've made a small script using Bounds (Link to Docs).

You can download my scripts as an .unitypackage including an example !

Let me know if you need any help :)


pushobjectintobounds.zip (17.2 kB)
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

76 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

Related Questions

Is there any way to find connected vertices in a mesh which was imported from Blender? 1 Answer

Starter Asset Capsule gets stuck on corners 0 Answers

Is it possible to translate a NavMesh at runtime? 2 Answers

GameObjects on terrain change position at each execution 0 Answers

I need help about raycast and edges 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