• 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 samsamsam · Sep 11, 2013 at 11:07 AM · buildbuilding

in game building mechanic

Hi guys

I am creating a a game where you can collect parts and build objects to place on the terrain such as walls and what not and it is first person. My problem is the object placing when you build the object. I can instantiate the object at the raycast from the centre of the screen but I need some ideas on how I can get a transparent version of the object that sticks to the terrain no matter the angles and height and then when you press the build button it places the object there. Sort of like a starcraft style building mechanic but from the fps view point. Any help would be awesome. Thanks.

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

1 Reply

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

Answer by Jamora · Sep 11, 2013 at 11:17 AM

To get the transparent version, you need a material with an alpha of 0.5f (also a shader that supports transparency), or however transparent you want it to be.

Then you set the rotation and position of the ghost object like in this answer.

For the building part, you just instantiate it like you do now.

Comment
Add comment · Show 4 · 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 Fattie · Sep 11, 2013 at 11:34 AM 0
Share

indeed - it's quite an art form "placing objects" on really interesting environments.

avatar image samsamsam · Sep 11, 2013 at 11:59 AM 0
Share

I'm still a bit lost sorry Jamora, I'm not quite certain on how to implement this correctly. This is the code I have and it may be way off.

 var bednaPrefab : Transform;
 var cam : Transform;
 var lastObject : Transform;
 private var drawGUI = false;
 
    
 function Update () 
 {
      var mousex = Input.mousePosition.x;
     var mousey = Input.mousePosition.y;
     var ray = camera.main.ScreenPointToRay (Vector3(mousex,mousey,0));
     var hit : RaycastHit;
  
     if (Physics.Raycast (ray, hit, 200)) 
     {
          
     }
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))
     {
         drawGUI = true;
         var clone = Instantiate(bednaPrefab, Vector3(0,0,0), Quaternion.identity);
         clone.transform.parent = cam;
         clone.transform.localPosition = Vector3(0,0,0);
         lastObject = clone;
      }
      if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.E))
      {
          lastObject.transform.parent = null;
          drawGUI = false;
      }
      dist = Vector3.Distance(cam.position, lastObject.position);
     if (dist <= 0)
     {
             clone.transform.localPosition = Vector3(0,0,0);
     }
 }
 
 function OnGUI()
 {
     if (drawGUI)
     {
         GUI.Box (Rect (Screen.width*0.5-55, 200, 110, 22), "Press E to Build");
     }
 }
avatar image Jamora · Sep 11, 2013 at 02:57 PM 0
Share

I'm a proponent for a don't-give-working-code policy in UA (well, with a few caveats), so I will only give you two pointers on how to achieve what you want...

Firstly, you should update the position of the newly-instantiated GameObject inside if (drawGUI == true) so you can move it around. You should move the raycast inside that if-clause to get the position. I assume that is why you're doing the raycast.

Secondly, you'll need to assign the transparent material to the object on instantiation, then the normal material on its actual placement.

avatar image samsamsam · Sep 26, 2013 at 12:39 AM 0
Share

Late reply but thanks heaps Jamora, you're a legend. Exactly what I needed to get it done!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Distribute terrain in zones 3 Answers

UWP build not working 1 Answer

Unity standalone build removes PDB files from output folder 1 Answer

Why does the player settings for a project not override previous default resolutions? 0 Answers

Game takes 3-4 hours to build. 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