Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vectrosity - fast and easy line drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, May 26, 2010.

Thread Status:
Not open for further replies.
  1. Charbl

    Charbl

    Joined:
    Sep 28, 2011
    Posts:
    17
    I've changed it so it now only calls DrawLine3D Auto, and I went back to the .3 calls and changed them to '3' -- The result is actually much worse :(



    Code (csharp):
    1.  
    2. function createLines()
    3. {
    4.    
    5.     xLine = new VectorLine("X Axis", new Vector3[2], Color.red, Resources.Load("LineMaterials/DashLine"), 3);
    6.     yLine = new VectorLine("Y Axis", new Vector3[2], Color.green, Resources.Load("LineMaterials/DashLine"), 3);
    7.     zLine = new VectorLine("Z Axis", new Vector3[2], Color.blue, Resources.Load("LineMaterials/DashLine"), 3);
    8.     Vector.DrawLine3DAuto(xLine);
    9.     Vector.DrawLine3DAuto(yLine);
    10.     Vector.DrawLine3DAuto(zLine);
    11. }
    12.  
    13. function Update ()
    14. {
    15.  
    16.          if (xLine)
    17.     {
    18.         xLine.points3[0] = Vector3(0, transform.position.y, transform.position.z);
    19.         xLine.points3[1] = Vector3(2048, transform.position.y, transform.position.z);
    20.         //Vector.DrawLine3DAuto(xLine);
    21.            
    22.         yLine.points3[0] = Vector3(transform.position.x, 0, transform.position.z);
    23.         yLine.points3[1] = Vector3(transform.position.x, 2048, transform.position.z);
    24.         //Vector.DrawLine3DAuto(yLine);
    25.            
    26.         zLine.points3[0] = Vector3(transform.position.x, transform.position.y, 0);
    27.         zLine.points3[1] = Vector3(transform.position.x, transform.position.y, 2048);
    28.         //Vector.DrawLine3DAuto(zLine);
    29.     }
    30.     }
    31. }
    32.  
    Here's the result of that same code with null material instead of dash line:

     
    Last edited: Sep 29, 2011
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Is that the scene view? It will only look right in the game view. Also, a dashed line will have the texture stretched out along the entire line, unless you use Vector.SetTextureScale.

    --Eric
     
  3. Charbl

    Charbl

    Joined:
    Sep 28, 2011
    Posts:
    17
    That's the game view, unfortunately. What puzzles me the most is that the green line on the Y axis works fine, but the other two distort on camera movement and are way too large.


    Here are two more shots -- I noticed that at a distance the lines eventually become and stay the right size.. here's the same scene, in Game view, from 2 different zoom levels:

    Far away:


    Close up:
     
    Last edited: Sep 30, 2011
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Try making the lines shorter and see if that helps (or make them have more than one segment). If that's not it, do you have a multi-camera setup? In that case, it's a little trickier to setup so that the lines adjust to the correct camera. (i.e., you usually have to use SetCamera instead of it just working with Main Camera.)

    --Eric
     
  5. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981

    Eric,

    It's been a couple of weeks, and I was hoping that you had fixed this issue. I am now about 3 days away from my final build of the project - hoping to release it next week. It would rock if you would fix this one bug with MakeSplineInLine(). Hopefully, I've given you the exact location of the bug and even a way to fix it.

    Would you please look at the suggested code fix above and make sure that it's the right way to do it?

    Thank you kindly.
    Gigiwoo.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, as I explained, it needs to be that way, it's not a bug. It's actually for this exact reason that the source is provided, so that you can adapt the code as you need to in particular cases. I will of course fix all actual bugs.

    --Eric
     
  7. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    I get it,today~ :)
     
  8. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi Eric,

    I hope this hasn't already been covered. This thread is huge (congrats!). We are building a very drawcall and performance sensitive game (iOS, for now). I could see us using Vectrosity for the simplest laser-like beam to drawing half the game, I just need to understand it a bit better.

    1) Can I somehow use UVs from a 3D package like Maya so i can atlas lines with other objects to batch drawcalls? Everything would be done in 3D space and it would need to sit in the world (a beam would have to go behind some stuff and in front of others, and not just in a clean z depth layering scenario, but true 3D), so batching is the tricky part for us.

    2) What do you think of the performance differences of drawing a grid which is static (my camera moves but the gird would never need to, is this possible?) versus a very low-resolution plane with a repeating square texture. Visual quality also has to be balanced of course. I think Vectrosity may create a sharper result without filtering, which I assume is a performance issue? I'm hoping you know because we are only just testing this part of for-iOS development.

    Let me know if you would be willing to hop on skype (screen-sharing) for a quick consultation, if this sounds like something Vectrosity can do. We would buy it at the 'pro' price simply for the consultation if you are willing. We wouldn't ask you to solve our problems, just a quick demo of our current project and a short back-and-forth for ideas so we can avoid some trial-and-error. PM me if you would rather go 'offline' with this.

    Cheers,
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    1) No, but I should point out that iOS isn't that sensitive to draw calls. It's only the first gen that needed to be so excessively careful with draw calls, but I assume you're not targeting first gen devices at this point.

    2) Moving camera/static grid is certainly possible, and if you want the grid as an overlay, that's what happens automatically by default, since lines are normally (though not necessarily) drawn with a separate camera. If you want the grid behind everything else, it's almost the same, you'd just have to manually change the rendering depths and clear flags of the cameras. As for performance, using Vectrosity to draw a grid vs. using a texture on a plane would have much better fill-rate, as well as being sharper. Some devices (iPhone 4, iPod touch 4th gen, iPad 1) are sensitive to fill-rate, since the GPU is underpowered for the number of pixels on the screen.

    --Eric
     
  10. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    1) Great information, thanks! I wish there were some guidelines. This is a Tower Defense game so it is easy to let drawcalls get out of control. I think I'm runing around 50 with a few hundred batched at the moment. I need to combine a few major atlases though (and i still don't know how particles fit in to all this). We would like this to run on 3Gs. I don't care about earlier devices.

    2) I'm thinking about using Vectrosity to draw our terrain (it is tron-retro-like with modern polish). I'm thinking I can output the simple geometry from Maya, put a simple shader on it for a "background" and use Vectrosity to draw the grid lines over it. I could let the first camera handle that and put my main camera above it.

    Did I read that Vectrosity has functions built in to draw a "wireframe" of a mesh? If I have "background" geo in there it wouldn't even need to cull hidden edges, though i suppose that could cut down on poly count...?

    Then what about the grid lines? Could I parse a mesh for the vertex points but not load it in to the game, and use the simple version with Vectrosity lines? I'm just brainstorming I could go with a simple grid if I have to, but I could get creative if I had an easy way to generate more complex grid-terrains.

    Anything you can suggest or share would be helpful. I'll pick this up in the next few days as soon as I get past my current tasks. I'm looking forward to playing with it!
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It has an editor utility for creating wireframes from meshes, and version 1.5 (not out yet) has a script function for automatically creating a wireframe from a mesh. Keep in mind that meshes in Unity are always triangulated; if you want quads, you need to use the utility and delete unwanted lines manually, or make some kind of custom function.

    Yes, though as I mentioned meshes are always triangulated in Unity, so assuming you don't want that, you'd need to make your own function for data parsing, though for a grid that's probably not hard.

    --Eric
     
  12. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Thanks for the info. I look forward to taking it for a spin!
     
  13. jeewanthasas

    jeewanthasas

    Joined:
    Sep 8, 2011
    Posts:
    13
    Hi,

    I just want to use your project to draw a curve path and remove that path when an object moves on that path.

    Could you please assist us to do that task with Vectrosicy. Is there any examples for this task?

    Thank you very much.

    Regards
    Sajith J
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The Path.js example script sounds like it's along those lines, if I understand you correctly?

    --Eric
     
  15. jeewanthasas

    jeewanthasas

    Joined:
    Sep 8, 2011
    Posts:
    13
    Hi, I've used that example (path.js ) and could you please let me know that how can i implement a line removing function (In a game like flight control system/ harbour master like path drawing game).

    I've already familiar with how to draw the path I just need to know how can I remove that path when an object moves towards that path. :confused:

    Do I need to use discrete path ?
    Is there any example for that ?


    Thank you very much.

    Regads,
    Sajith J.
     
  16. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    I've been using Vectrosity in my project for a while, and finally just updated the script (Its been a while obviously, since the latest rev is from July22!)

    Now, i'm getting an error on first import:

    Assets/Vectrosity/Scripts/Xray/XRayLineData.js(1,18): BCE0018: The name 'XrayLineData' does not denote a valid type ('not found').
     
  17. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Also a thought moving forward, since there isn't any real useful namespaces (as far as i know?), Path.js is probably not the best choices of Class name, as it then conflicts with any 'using System.IO; / Path.GetFile...whatever functions.

    Currently removing parts of your package so as to not cluster-fsck my previously existing scripts.
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's not from the current version, so you can remove it.

    That's just one of the demo scripts, and isn't something you'd be using elsewhere. Only the core Vectrosity scripts in Standard Assets should normally be used in other projects.

    --Eric
     
  19. Werit

    Werit

    Joined:
    Dec 12, 2010
    Posts:
    38
    Eric,

    Is it possible to do 2D drawing? I'd like to hide the mouse cursor, at times, and draw a circle instead as the mouse cursor. At the same time, I'd like to be doing 3D draws in the game world.

    Thanks!
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sure, Vector.DrawLine is 2D. Only if you use DrawLine3D will it be in the game world.

    --Eric
     
  21. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric,

    Just now getting around to upgrading to 1.4.2 and I am getting a bunch of errors:

    I seen in your documentation that c# users need to specify "ref", but I am using JS.

    Thoughts?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, as it says, you need to use VectorLine and not Object. That's always been the case, though...it sounds like your issue is probably with using #pragma strict when you weren't before. Just make sure your variables are typed correctly, either explicitly or by type inference, which is always good practice regardless.

    --Eric
     
  23. jeewanthasas

    jeewanthasas

    Joined:
    Sep 8, 2011
    Posts:
    13
    Hi, I've used that example (path.js ) and could you please let me know that how can i implement a line removing function.

    I've already familiar with how to draw the path I just need to know how can I remove that path when an object moves towards that path.

    Do I need to use discrete path ?
    Is there any example for that ?


    Thank you very much.

    Regads,
    Sajith J.
     
  24. azeitler

    azeitler

    Joined:
    May 14, 2008
    Posts:
    162
    I am using 1.4.2 but I still can't get the lines to fill the edges.
    This is the code I am running:

    Code (csharp):
    1.  
    2. line = new VectorLine("line", nodes, someMaterial, 5f, LineType.Continuous, Joins.Fill);
    3. Vector.DrawLine3D(line);
    4. Vector.SetTextureScale(line, 1f);
    5.  
    Anything I am doing wrong?
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not sure I quite followed that, but you can remove any line that you create using the Vector.DestroyLine function. If you're talking about individual line segments, you can alter the array of points that makes up the line at any time, plus VectorLine.minDrawIndex and .maxDrawIndex can be helpful in some cases. The logic that you might implement depends on what sort of effect you're after exactly, and what else you've done with your game or app.


    What are you using for the "nodes" variable? I tried it with "var nodes = [Vector3.zero, Vector3.one, Vector3(2, 0, 0)];" as a test, and it works as I would expect.

    --Eric
     
  26. xfingerx

    xfingerx

    Joined:
    Feb 12, 2011
    Posts:
    4
    Greate!
     
  27. azeitler

    azeitler

    Joined:
    May 14, 2008
    Posts:
    162
    Eric, thanks, the problem was indeed in the nodes-Array (I added each point two times – a hotfix remaining from an earlier revisions of Vectrosity).
     
  28. jeewanthasas

    jeewanthasas

    Joined:
    Sep 8, 2011
    Posts:
    13
    I've used the code (DrawLinesMouse.cs) for the task, but it is not functioning as I expected.
    Please let me know any suggestion.


    if(travellerpath.getIsMouseDragFinished())
    {
    Debug.Log("moving" + lineIndex.ToString());
    Vector.ZeroPointsInLine(line,lineIndex);
    }

    I've just added the last if block for removing the line and also used the line type as LineType.Discrete as mentioned above.

    Could you please let me know how can I alter this code block for functioning properly ?
    Please refer to the screen shot and I just need to remove the path points dynamically when the object (cube) moves on that path.
    Cheers...
     

    Attached Files:

    Last edited: Nov 11, 2011
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not really sure what you're trying to do exactly, but it sounds like you want to be setting individual items in the linePoints[] array to Vector2.zero, instead of using ZeroPointsInLine.

    --Eric
     
  30. jeewanthasas

    jeewanthasas

    Joined:
    Sep 8, 2011
    Posts:
    13
    Hi,

    Thank you for your quick reply.

    Yes. I don't want to remove the entire line at once. I just want to remove the points of the line when the object moves towards the line as in a game like flight control system.

    Simply,
    1) I touches the screen and drag the screen to draw a path
    2)When I finishes the drag, object is moving on that path.

    While moving the object (acts like an eraser), I need to remove those points of the line

    After completing the movement of the object, entire path should be removed .

    In this case the object acts like an eraser

    Could you please make any suggestion ?
    Cheers...
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like just increasing the .minDrawIndex as the object travels along the path would do it.

    --Eric
     
  32. jeewanthasas

    jeewanthasas

    Joined:
    Sep 8, 2011
    Posts:
    13
    Hi Eric,

    It is not functioning as I expected. Simply, please let me know how can I implement a line eraser type function using Vectrosity.

    ** I need to draw a line as in your draw-line example using touch OR mouse-drag input
    ** Then I need to erase the line using a game object which act as an eraser.

    Thank you very much.

    Regards,
    Jeewanthasas
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I think I've answered this as well as I can. I would increase the .minDrawIndex as the game object moves along the path (the .maxDrawIndex should be set to the end of the line), that way the line "disappears" from the beginning. The other option would be to progressively zero out the entries in the array used for the line, but it seems to me that just increasing .minDrawIndex would be simpler and more efficient.

    --Eric
     
  34. LegionLover

    LegionLover

    Joined:
    Nov 25, 2011
    Posts:
    1
    Eric,

    Sorry to have to ask this if it's been brought up on this thread before, but I can't seem to find the answer. I'm using Vectrosity 1.4.2 and having Line Maker generate arrays of vertices that I then use in my code (I'm placing meshes in space and adding a trigger collider to each vertex).

    Although the documentation for Line Maker says that I should rotate and scale the mesh prior to running Line Maker, the rotate and scale properties seem to be ignored. As a test, I'm using a standard cube mesh from Unity where each vertex's is .5 (pos or neg) from the center of the cube. Even when I scale the cube up, the resulting array still shows Vector3(0.5, -0.5, 0.5), etc. Do I have to do some conversion to World space before saving the line to file? I'm attaching the script to an empty game object, but no matter what I do, the resulting lines are always drawn unscaled, unrotated at 0,0,0 in World space.

    thx!
     
  35. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    I love this. And only $25? Steal!

    Great work!
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're right; sorry about that. In the ComputeLine function, replace this:

    Code (csharp):
    1. var p1 = Vector3Round(objectTransform.InverseTransformPoint(linePoints[i].p1));
    2. var p2 = Vector3Round(objectTransform.InverseTransformPoint(linePoints[i].p2));
    with this:

    Code (csharp):
    1. var p1 = Vector3Round(linePoints[i].p1 - objectTransform.position);
    2. var p2 = Vector3Round(linePoints[i].p2 - objectTransform.position);
    $20 on my site. ;) (Or $35....)

    --Eric
     
  37. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    Yeah, was gonna go with your store when I saw it. But I like it in my unity account :).
     
  38. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Is there anything for drawing a curve by supplying just the points, as opposed to having to generate handles for every point?

    Edit: looks like i haven't updated the version in a while, I didn't see the MakeSplineInLine function! yay.
     
    Last edited: Dec 1, 2011
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Why yes, yes there is. ;)

    --Eric
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Version 1.5 is done!


    Vectrosity 1.5

    Additions:
    • Vector.MakeWireframeInLine, for making automatic wireframes from a mesh. Essentially the same as if you used the LineMaker utility on an object and clicked "Connect all points", except you can use it at runtime on arbitrary meshes. (Note: not animated meshes, sorry; that's impossible because the state of animated meshes can't be read in Unity.)
    • Vector.DrawLineViewport, for drawing 2D lines with normalized viewport coordinates. This works like the coordinates for GUIText and GUITexture, where (0.0, 0.0) is the lower-left corner, and (1.0, 1.0) is the upper-right corner. This means lines drawn with DrawLineViewport will be in the same relative position regardless of screen resolution. e.g, using [Vector2(.5, .5), Vector2(1.0, .5)] will always result in a line that starts in the middle of the screen and ends at the right edge.
    • Vector.GetLinePoint and Vector.GetLinePoint3D, for getting a position on a 2D or 3D line based on length. Can be used for things like making an object travel along a spline at a constant speed.
    • Vector.GetLinePoint01 and Vector.GetLinePoint3D01: as above, but you can use a 0..1 percentage length instead of unit length. e.g., using 0.5 returns a point halfway along the line.
    • Vector.GetLineLength, which returns the total length of a given line.
    • Vector.SetLineDistances: use this if you've changed the position of any points in a VectorLine after using GetLineLength, GetLinePoint, etc. and want to use those functions again. For performance reasons this isn't done automatically.
    • In addition to being used for GameObject and mesh names, the "name" property is now directly available for VectorLines. e.g., Debug.Log(myLine.name);. Changing the VectorLine name property will change the GameObject and mesh names appropriately.

    Changes:
    • Requires Unity 3.4.
    • Vector.Active replaced with VectorLine.active, so it's more consistent with the way Unity works. e.g., myLine.active = false.
    • Vector.SetColorsSmooth can now be used even if the line wasn't created with colors originally.
    • Vector.SetWidths can use an int array now for the line widths (instead of only a float array).
    • VectorLine.continuousLine is now VectorLine.continuous, since "continuousLine" was kind of redundant in context.

    Fixes:
    • Vector.DestroyLine works with VectorPoints again.
    • Rotation and scale for objects used with the LineMaker utility is properly respected when generating lines.

    -----------

    Update notices are going out now. My web host can only send so many emails per hour, so it will take a while...if you don't get anything by, say, tomorrow (and you're sure you had update notices turned on), let me know. If you don't want to wait, and you still have a previous update notice, you can use the download link in that email and it will download the latest version. Also I'll be submitting the update to the Asset Store shortly. Happy line-drawing!

    --Eric
     
  41. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    sweet update! you should have a commercial page or something so people can spot it being used in published unity projects.
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As a matter of fact, that thought came to me when I was looking at the screenshots for Physynth.

    --Eric
     
  43. handsomePATT

    handsomePATT

    Joined:
    Nov 30, 2010
    Posts:
    574
    Hey just started using Vectrocity and I get an error. If the player loses it goes back the a menu. If they hit restart and it reload the scene I get the error/

    Code (csharp):
    1. MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it.
    2. Your script should either check if it is null or you should not destroy the object.
    3. UnityEngine.Camera.WorldToScreenPoint (Vector3 position)
    4. Vector.Line3DContinuous (.VectorLine line, Int32 end, Matrix4x4 thisMatrix, Boolean doTransform) (at Assets/Scripts/VectorScripts/Vector.cs:690)
    5. Vector.DrawLine (.VectorLine line, UnityEngine.Transform thisTransform) (at Assets/Scripts/VectorScripts/Vector.cs:564)
    6. Vector.DrawLine (.VectorLine line) (at Assets/Scripts/VectorScripts/Vector.cs:532)
    7. Vector.SetLine (Color color, Single time, UnityEngine.Vector3[] points) (at Assets/Scripts/VectorScripts/Vector.cs:490)
    8. Vector.SetLine (Color color, UnityEngine.Vector3[] points) (at Assets/Scripts/VectorScripts/Vector.cs:478)
    9. LineTrail.Initialize (UnityEngine.Transform trans, Color trailCol, Int32 lineWidths) (at Assets/Scripts/Weapons/Extensions/LineTrail.cs:14)
    10. MissileBase.Initialize (Color trailColor, Int32 lineWidth) (at Assets/Scripts/Weapons/Base/MissileBase.cs:13)
    11. ClusterMissile.Start () (at Assets/Scripts/Weapons/Enemy/ClusterMissile.cs:12)
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's probably best if you use DontDestroyOnLoad, but see the section in the docs about setting the camera, which you may have to do manually after changing scenes.

    --Eric
     
  45. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Get cracking then, and feel free to abuse anything I've made :D
     
  46. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric,

    You have an excellent example of a splineFollow scene in the scenes shipped with Vectrocity. In SplineFollow3D.js, you have a cube making its way through a spline at constant velocity. I'd like to see if I could make the cube move through the spline at a varying velocity. Maybe set a velocity at each sphere and the speed of the cube is interpolated between spheres (or something like that). How would you go about doing that?

    Thanks!

    Tom
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    One way would be to have an array of distances, and an array of speeds. You can check the total distance traveled every frame against a value in the distance array, and when it's exceeded, increment the array index so it will check against the next value. The speed would come from the matching speed array using that same index.

    --Eric
     
  48. KnuckleCracker

    KnuckleCracker

    Joined:
    Dec 27, 2011
    Posts:
    80
    Just tried Vectrocity (Pro) with the developer preview of Unity 3.5. Things aren't working so great when trying to publish to the new Flash build target.

    You get this error when compiling:
    ...Temp\StagingArea\Data\ConvertedDotNetCode\global\Vector.as(1974): col: 41 Error: Ambiguous reference to Vector.

    This is likely because "Vector" is an intrinsic data type in flash and collides with the Vector class in Vectrocity. Maybe there is a workaround (I'm all ears)... but my guess is that the only solution will be for Vectrocity to use a more specific name for at least the Vector class.

    This is a shame since I was really itching to see what the performance of Vectrocity would be when publishing to a flash target. I suppose I can just start renaming classes and fixing references...
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, that's annoying. Although it does give me more incentive to merge Vector into VectorLine, which I've actually been wanting to do for a long time, the main issue being that it will break 100% of existing Vectrosity code that people have written. I don't quite know why I have it separate anyway, except for the usual "apparently it seemed like a good idea at the time". As a result of the merge, for example,

    Code (csharp):
    1. Vector.DrawLine(myLine);
    would become

    Code (csharp):
    1. myLine.Draw();
    Things like

    Code (csharp):
    1. Vector.MakeRectInLine(myLine, myRect);
    would become

    Code (csharp):
    1. myLine.MakeRect(myRect);
    And so on. So coding would be simpler and it would presumably fix that ambiguous reference error. But, like I said, all existing Vectrosity user code would have to be rewritten.

    --Eric
     
  50. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Hi! I cant get this thing to work,at least do not get the result i want, it seems that i just do not get it. i need some help here please!

    what i am trying to do is to render 3d line with 3d points converted from screen to world space based on touches.
    the result i get is line but not in the position i want. also VectorCam position is strange.

    here is what i did:

    declare VectorLine and two 3D points
    Code (csharp):
    1. private var aimVector : VectorLine;
    2. private var originVector : Vector3;
    3. private var destinationVector : Vector3;
    here i set the camera, documentation say that
    i do not need to do anything while camera's i use is "MainCamera
    the camera i use has orthographics projection
    Code (csharp):
    1. function Awake(){
    2.   Vector.SetCamera();
    3. }
    here is set vectors and line (this displays good, where it should be when i start the game)
    HTML:
    function Start(){
    	originVector=Vector3(0,0,0);
    	destinationVector=Vector3(1,10,0);
    	aimVector=Vector.SetLine3D(Color.green,originVector,destinationVector);
    }
    but as soon as i update the origin or destination vector line dissapears (it shows outside the camera view, and reacts good on input if i search for it in the scene view)

    here is the part where i update vectors (this function executes from Update()):

    Code (csharp):
    1.  
    2. function UpdateVectors(){
    3.  
    4.         handlePos.x=touchPosition.x;
    5.     handlePos.y=Screen.height-touchPosition.y; 
    6.    
    7.     handlePos=ClampPositionToCircle(controlPos,controlDim.x/2,handlePos);
    8.    
    9.     destinationVector=cam.ScreenToWorldPoint(Vector3(handlePos.x,handlePos.y,0));
    10.     aimVector.points3[0]=originVector;
    11.     aimVector.points3[1]=destinationVector;
    12.     Vector.DrawLine(aimVector);
    13. }
    14.  
    so i do not really know what is going on, it could be that i misusing ScreenToWorldPoint,clipping planes are wrong,ortho camera does not work here, etc...i do not really know.

    any help appreciated!
     
Thread Status:
Not open for further replies.