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 Triqy · Jun 27, 2013 at 12:42 AM · instantiateraycastbuilddistancecreate

[Closed] Instantiate wall/fence down a raycast from point A to point B?

I need to be able to create a wall from point A to point B between two placeable marker points. This is what i have on Point A marker:

 #pragma strict
 //point B Marker
 var target: Transform;
 public var Wall: Transform;
 
 
 var create = false;
 
 function Start () {
 
 }
 
 function Update () {
 
 
 
 if(create == true){
 
 var relativePos = target.position - transform.position;
 var distance = Vector3.Distance(target.position, transform.position);
 var ModelsNeeded = distance / 10.0;
 
 print ("Distance to other: " + distance);
 
 for (var i : int = 0;i < ModelsNeeded; i++) {
 Instantiate (Wall, Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.LookRotation(relativePos));
 
 create = false;
 }
 
 }
 
 
 if(Input.GetKeyUp("space")){
 
 create = true;
 
 }
 
 
 transform.LookAt(target);
 
 var fwd = transform.TransformDirection (Vector3.forward);
 var hit : RaycastHit;
 
 
 if (Physics.Raycast (transform.localPosition, fwd, hit, Mathf.Infinity)) {
 
     Debug.DrawRay (transform.position, fwd * hit.distance, Color.green);
 
 }
 }


what this does right now is it allows me to get the distance between point A and point B, but only instantiates wall at point A position. I need it to follow the raycast all the way down to point B. I hope that makes sense thanks. - Brady

Comment
Add comment · Show 10
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 Triqy · Jun 27, 2013 at 12:47 AM 0
Share

So the line that the problem is on i believe is at line 26. On this line i have it where when it instantiates all the walls created are at position point A marker and does not follow to point B marker? What to i need to Find var wise or what do i need to change?

avatar image Triqy · Jun 27, 2013 at 12:51 AM 0
Share

another note is that the wall is 10 units wide and i want to instantiate down a say 50 unit long distance... so i will need 5 walls segments.

avatar image iwaldrop · Jun 27, 2013 at 01:10 AM 0
Share

You're not offsetting the walls you instantiate by their width. Are you sure that there aren't 10 segments all in the same place?

avatar image iwaldrop · Jun 27, 2013 at 01:11 AM 0
Share

Also, ins$$anonymous$$d of setting a flag to check every frame, just make a method that creates wall segments. When the space key goes up, just call the method.

avatar image Triqy · Jun 27, 2013 at 01:18 AM 0
Share

Hmm...Heres how i have it right now. When I click on the terrain/plain it creates $$anonymous$$arker A. Ill move the mouse and click again which creates marker B. I want to be able to create wall segments between $$anonymous$$arker A and $$anonymous$$arker B. So what do i need to use?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

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

Instantiate gameobject a certain distance away from transform 2 Answers

Position before the camera? 2 Answers

Distribute terrain in zones 3 Answers

How do i instantiate along the z axis? 3 Answers

Raycast Specific Object/Instantiate Explosion 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