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 CaKeMeaT · Jan 29, 2015 at 09:34 PM · instantiatequadmagnitude

Stretch a Quad from one object to another

I am wondering what a good efficient way to Instantiate a simple textured Quad between two objects. (Think of a lightning arc reaching from GO to enemy GO;

I have a basic setup like in: http://docs.unity3d.com/Manual/DirectionDistanceFromOneObjectToAnother.html

But am curious how I would get the prefab(quad) to stretch the distance of the magnitude, bonus if I can get the angle to be more precise, and flatten the rotation so the quad is flat almost parallel the ground.

 void OnTriggerEnter(Collider hit)
     {
         if (hit.gameObject.tag == "enemy") {
             Debug.Log("lightning orb hit enemy");
             my_enemy_hit = hit.gameObject;
             assign_target(my_enemy_hit);
 
             // TURN TOWARDS
             Vector3 targetDir = my_target_transform.position - transform.position;
             float turn = 10 * Time.deltaTime;
             Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, turn, 0.0F);
             //Debug.DrawRay(transform.position, newDir, Color.red);
             transform.rotation = Quaternion.LookRotation(newDir);
             // create fx
             //Vector3 newdir = transform.position - my_target_transform.position;
             //newdir.x = 0;
             //var magni = newdir.magnitude;
 
             Quaternion newquat = Quaternion.LookRotation(newDir);
             //Vector3.MoveTowards(transform, my_target_transform, 1.0f);
 
             Instantiate(lightning_fx01_src, transform.position, newquat);
             hit_lightning_orb(my_enemy_hit, 1);
             rigidbody.velocity = Vector3.zero;
         }
         
     }
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
0

Answer by Cherno · Jan 30, 2015 at 01:48 AM

This could be a starting point; no scaling, it directly moves the vertices.

 //assign these variables yourself, depending on how you want your quad to stretch
 Vector3 startPos1;
 Vector3 startPos2;
 Vector3 endPos1;
 Vector3 endPos2;
 
   
 Mesh mesh = GetComponent<MeshFilter>().mesh;
 Vector3[] vertices = mesh.vertices;
 //switch around where the start and end positions go, just try it out until all four vertices go to the right positions
 vertices[0] = new Vector3(startPos1);
 vertices[1] = new Vector3(startPos2);
 vertices[2] = new Vector3(endPos1);
 vertices[3] = new Vector3(endPos2);
 mesh.vertices = vertices;
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 ShawnFeatherly · Jun 14, 2015 at 08:43 AM

This re-positions a quad using two Vertor3's. As long as the Vector3's have the same Y value, it results in a quad that's facing up and parallel to the ground.

 private void stretchQuad(GameObject quad, Vector3 start, Vector3 end, float lineWidth = 0.3f)
 {
     quad.transform.position = Vector3.Lerp(start, end, 0.5f);
     quad.transform.LookAt(end);
     quad.transform.Rotate(90, 0, 0);
     quad.transform.localScale = new Vector3(lineWidth, Vector3.Distance(start, end), 1);
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Checking if object intersects? 1 Answer

Help, can't get Grid to instantiate in the center of the screen 0 Answers

Instantiating prefabs, when there is nothing 2 Answers

Material Switching Upon Instantiation. over my head 0 Answers

continuous shooting 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