- Home /
radar orthogonal line to plane
hi guys I've created a radar my self, for a spaceship simulator that I have created
the Radar was created from 4 gameobjects: 1. radar - sphere (parent) 2. center - plane 4. centerPoint - small sphere that indicates point 0,0,0 in the radar (sphaceship location in the radar) 5. enemies points - list of small spheres that represents the enemies
Im trying to streach a line from the enemies points to the center plane that indicates the object relative height (relative to the spaceship because its space) but so far without success
any help will be appreciated
thanks in advance
Gal
Can you share an image or something that will make clear as to what you have achieved currently and what you want?
I think what you can do is draw a line using LineRenderer that takes two points - one is the enemy sphere's position and another is point on the center plane (the position of plane itself?).
the thing is Im trying to draw an orthogonal line from the dots to the plane (not the spaceship)
I have tryid to use line renderer and i think this is the right way but how do i find the second edge of the line (the one on the plane)
Answer by HarshadK · Jun 09, 2015 at 09:48 AM
If your plane is always going to be perpendicular to the world Y axis then you can just perform a Raycast from the position of enemy ship sphere in world y axis direction. Now where this raycast intersets your plane will be the point on the plane is your second point. Now you can draw a line using Line Renderer with first point being the position of enemy ship sphere and second point we calculated above.
If your plane is not always perpendicular to the world Y axis then you would need to use Vector Projection to calculate this second point on the plane to draw the line.
is there a tool in unity that helps me calculate the vector projection?
No there is no direct method that will provide you with vector project. But there is just another way you can do it. Just find out the normal of the plane (up direction of transform in this case will do the trick). Now perform a raycast towards the plane and where this raycast hits the plane is your second point. Below is the test code for the same. You just have to make necessary changes to as per your structure and replace the Debug.DrawLine method with drawing the line with a Line Renderer. For this current code to work it has to be attached to the plane since it takes the transform of plane directly to work things out.
// The transform of your enemy spaceship
public Transform enemy;
void Update () {
// Get the up direction of transform and decide the direction based off the position of plane with respect to the enemy ship
Vector3 dir = (transform.position.y < enemy.position.y) ? (-transform.up) : transform.up;
RaycastHit hit;
if(Physics.Raycast(enemy.position, dir, out hit))
{
// Draw the line between enemy ship position and hit point.
Debug.DrawLine(enemy.position, hit.point, Color.green, 0.1f);
}
}
Your answer
Follow this Question
Related Questions
How to make a wavy circle? 0 Answers
Radar script help 2 Answers
How do I make a particle system follow a function? 1 Answer
Creating a parabola line in 3D Space 1 Answer
How to calculate inner vertices of a line renderer? (math question) 1 Answer