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 Amara · Jan 20, 2016 at 06:36 PM · c#linerendererplanecollide

Drawing line from plane edge

I am trying to draw a line from one object to a target object. i have managed to do this however the lines are drawn from the centers

what i would like to do is draw the lines from the edge of a plane to the edge of a plane on the target

http://imgur.com/7eueSh9

In this image the white lines are the currently drawn connection and the red lines are how i would like the lines to be drawn

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 SterlingSoftworks · Jan 20, 2016 at 07:00 PM 0
Share

https://www.youtube.com/watch?v=$$anonymous$$bW$$anonymous$$8bCAU2w

Check this tutorial out. This might be able to help you set up those rays based on the edges of the planes at least.. Not so sure about sending the rays to hit the other edges though.

You could also set up 4 empty objects on the edges at the centers and fire rays based on which object is closest? Don't quote me too much on these solutions though, just thinking of how I'd try to do it.

P.S. Sick lookin' game you're working on!

avatar image Amara SterlingSoftworks · Jan 20, 2016 at 10:20 PM 0
Share

Thanks you : )

avatar image Fattie · Jan 20, 2016 at 09:03 PM 0
Share

In general in the first place you should carefully learn about

Bounds

$$anonymous$$ake sure you learn properly, and be sure to understand the difference between renderer bounds, and the others.

And yeah your game looks O$$anonymous$$. Don't get cocky.

1 Reply

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

Answer by Masterio · Jan 20, 2016 at 08:30 PM

Maybe this helps:

http://docs.unity3d.com/ScriptReference/Mesh-bounds.html

Attach this sctript on the plane

 using UnityEngine;
 using System.Collections;
 
 public class GetBounds : MonoBehaviour 
 {
     Vector3 targetPoint = Vector3.zero;
 
     public void OnDrawGizmos()
     {
         Mesh mesh = GetComponent<MeshFilter>().mesh;
         Bounds bounds = mesh.bounds;
         
         // not affected by scale or rotation
         Debug.Log ("x: " + bounds.size.x +" y: "+ bounds.size.y + " z: " + bounds.size.z);
         
         // next you can simply calculate the start point of the ray
         Vector3 edgeA = transform.position + new Vector3(bounds.size.x * transform.localScale.x / 2, 0, 0);
         Vector3 edgeB = transform.position - new Vector3(bounds.size.x * transform.localScale.x / 2, 0, 0);
         Vector3 edgeC = transform.position + new Vector3(0, 0, bounds.size.z * transform.localScale.y / 2);
         Vector3 edgeD = transform.position - new Vector3(0, 0, bounds.size.z * transform.localScale.y / 2);
 
         // next if plane is rotated you must calculate position for this rotation...
         edgeA = RotatePointAroundPivot(edgeA, transform.position, transform.localRotation.eulerAngles);
         edgeB = RotatePointAroundPivot(edgeB, transform.position, transform.localRotation.eulerAngles);
         edgeC = RotatePointAroundPivot(edgeC, transform.position, transform.localRotation.eulerAngles);
         edgeD = RotatePointAroundPivot(edgeD, transform.position, transform.localRotation.eulerAngles);
 
         Gizmos.color = Color.red;
 
         Gizmos.DrawLine(edgeA, targetPoint);
         Gizmos.DrawLine(edgeB, targetPoint);
         Gizmos.DrawLine(edgeC, targetPoint);
         Gizmos.DrawLine(edgeD, targetPoint);
     }
 
     private Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
     {
         Vector3 dir = point - pivot;             // get point direction relative to pivot
         dir = Quaternion.Euler(angles) * dir;     // rotate it
         point = dir + pivot;                     // calculate rotated point
         return point;                             // return it
     }
 }
 



It looks like this:

http://s13.postimg.org/h1cz5vfyf/bounds.jpg

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to check for a collisoin between objects 1 Answer

Creating randomly disappearing floor tiles 0 Answers

Draw shortest distance between 2 points on a sphere 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