Hi, I’m new to unity and C#, just got into a project where the code is already made for some part.
I’ve got a new requirement to do on unity and have no clue, please help.
Question is: How to draw flat oval? Given 2 anchor, point A (0,0,0) and point B(1,1,1), I’ll have to draw a flat oval between them so it’s look like this:
The purple dashed-line is what I need to make, but I have no idea how to draw that line at all. What kind of code should I make? At least can someone demonstrate on how to draw a simple flat oval first? Then I’ll figure out how to make it anchored to the correct points. I don’t even know how to make dashed-line, not to mentioned dashed-flat-oval with correct anchored points.
If this is some kind of homework or assignment you are at the wrong place.
Line drawing can be done with LineRenderer component. A bit more versatile is (paid) Vectrosity package from the AssetStore. Or you could create a custom mesh.
For the shape I would use a half circle around the points and the region in between is just a straight line.
If this does not help you you will need to get a bit more specific about what you need help with.
I’m iOS developer, and this is the task I got for the embed unity inside my native app. Someone developed that before and now I gotta do this task because he left.
I may understand what you’re talking about, but can you demonstrate some code? I’m trying to use LineRenderer following this guide. However, there are lots more to the task. E.g. need to calculate the angle between the points, draw half a circle around 2 ends and 2 straight lines between, then make it dashed-line.
Let’s say, in the main Scene, I’ve created this method:
private void DrawPath(Vector3 p1,Vector3 p2) {
}
What should I put inside the function to draw the line?
I have not laying around this specific code. Even if I did this is not how this forum works. Just asking for code is a no-go. Low effort posts are against the rules !.
Thats the part of devloping software. Just start with the most simple thing (fe just draw a line between the two points) and expand upon that, step by step. Look in the documentation which methods may help you. Look for some tutorials about the sub-steps you mentioned.
Most people here are hesitant to spoon-feed “lazy” people which show no own effort. Also this is the scripting subforum. So code is discussed here. An empty method body is nothing worth to discuss IMO. So if you want help you will have to come up with some code worth discussing.
Just asking someone else to write the code for you ist just annoying and, as I said, against the rules.
If you are beginner then head to the learning section and/or do some tutorials. Search about the topic.
GameDevelopment requires serious learning effort. The forum is not meant to teach you everything from scratch to save you this effort. You will have to show that you are willing/capable first.
That sounds a bit as you don’t understand your code? The curved parts use 200 points so thats pretty smooth. The lower left part looks like a straigt line. So maybe there is something messed up with the points or there is a bug in the code? Also the distance at the spheres looks closer than at the lines. Maybe that’s due to the bezier calculations (I’ve never worked with bezier curves). I would just use a semi circle there that would also prevent the sharp bend (not sure if that is the correct english term, I’m not native english speaker) where the round part hits the line part.
The method CalculateStartAngle seems to only consider x + z ordinate. I could imagine this fails in certain scenarios (for example when one point is above the other). Is this the formula you mentioned for 2d? If you have this “restriction” you should also only apply it for the 2d case. Your points have different heights (y values) so this is already not the case. You probably also want your line to adapt to the viewers position so you don’t watch it from the side? Or is the camera always looking down?
searching for “unity linerenderer dashed” reveals some possibilities:
Unity’s line renderer is a bit limited. As I already mentioned the paid package Vectrosity is THE solution for drawing lines. Since it comes with source code you could also deduce how it is implemented there. But mesh generation is not trivial.
Just found a Shader solution while browsing Blog of user @mgear . Have not dug into it (and am not proficient with shaders) but it seems you just need to draw a line between the two points. Give it a look/try.