• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Getting my airplane to stay level? 0 Answers

Plane with Texture, show as fullScreen 0 Answers

Creating a LineRenderer: its always null 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges