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 Harper · Nov 21, 2012 at 07:36 PM · raycastprefabrts

Prerendering a mesh before you place it on the world?

So I know how to place a prefab based on the mouse position using a ray-cast, but how do I render the mesh in the prefab where the mouse is pointing before I place it on the world?

Also if anyone could tell me how I could make it so I cant place an object if one is already there. Should I use some type of box collier on my prefab attached with a trigger? How do I make the collision perfect and will it cause to much overhead?

Thanks

Comment
Add comment · Show 3
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 Harper · Nov 22, 2012 at 02:27 AM 0
Share

Thanks, I dont know why this didnt come to me lol

avatar image Harper · Nov 28, 2012 at 03:04 PM 0
Share

Thanks, sorry this is my first time using the website. Thank you for the tips.

avatar image AlucardJay · Nov 29, 2012 at 04:14 AM 0
Share

no worries, just saving you from getting downvoted. Happy Coding =]

1 Reply

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

Answer by sparkzbarca · Nov 21, 2012 at 07:47 PM

just actually spawn the object. move the object so its position is constantly the mouse position and disable collision so it shows up wherever. Make it semi transparent so the player realizes it hasn't been placed yet as far as the game is concerned.

When the player left clicks detach it and enable collision but first check to ensure nothing is in the way. If something is in the way don't allow it to detach or anything so they cant get it operating in the game.

perfect collision is done with an arbitrary shape by using a convex mesh collider. It does cause alot of overhead thats why most people don't make it perfect. :P

if you would like to know if something is there have a mesh collider or any collider and have it as a trigger not as a normal collider.

 OnTriggerEnter(collider other)
 {
 canBuild = false;
 }
 OnTriggerStay(collider other)
 {
 canbuild = false;
 }
 OnTriggerExit(collider other)
 {
 Canbuild = true;
 }


now when an object enters the meshs bounds and while it stays there it will set canbuild to false. you can use that bool to stop building.

You need the Ontrigger stay in case multiple objects are involved. you can't just used ontrigger enter and exit.

for example object a is inside mesh can build = false; object b is inside mesh can build = false; object a leaves the trigger can build = true; but object b is still in there, so you want the on trigger stay so after the object exits the object b sets canbuild to false again.

MARK AS ANSWERED have a good one. :)

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 Harper · Nov 22, 2012 at 01:28 AM 0
Share

thank you I didnt know about that Ontrigger stay. So I'm curious though, how do I make all my meshes in the game-world collide with this script without any overhead? Does everything have to be a trigger or can I use normal collisions?

Thanks

avatar image sparkzbarca · Nov 22, 2012 at 02:57 AM 0
Share

the only trigger is the collider BEFORE you spawn it into the world, during placement the collider should be a trigger.

other non-trigger colliders will cause the trigger collider to "trigger" as it were.

basically the difference between trigger and regular colliders is when regular colliders run into a collider they stop and when they run into a trigger they send a message but there movement isn't obstructed.

regular colliders define an area as occupied, trigger colliders just define it as specila.

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

11 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

Related Questions

Non uniform movement radius 1 Answer

Raycast shooting with prefab 0 Answers

How do I instantiate a projectile along the path of a raycast? 0 Answers

Destroying a prefab with a prefab? 2 Answers

Click to Move With Navmesh 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