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

ArcReactor procedural ray generator

Discussion in 'Assets and Asset Store' started by CatsPawGames, Jun 4, 2014.

  1. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    i have a problem, i currently am using the forge3d force field that detects hit points of a collider to show know where to show the shield effect, but has no code to detect line renderer hit points, how can i detect hit points of the laser using the message send from the launcher in c#

    very stuck getting it to work
     
  2. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    Hello.

    You can access .Rays list of Launcher - it's a public property that returns all rays launched by it. It's a list of RayInfo objects that contains all relevant information. To get final point of ray, you can use something like this:
    Code (CSharp):
    1. RayInfo ray = launcher.Rays[0];
    2. Vector3 lastPosition = ray.shape[ray.shape.Length-1].position;
    Since there's no guarantee that launcher is firing ray currently, you can also put a simple check like this:
    Code (CSharp):
    1. if (launcher.Rays != null && launcher.Rays.Count > 0)
    2. {
    3.        RayInfo ray = launcher.Rays[0];
    4.        Vector3 lastPosition = ray.shape[ray.shape.Length-1].position;
    5. }
     
    twobob likes this.
  3. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    i have a script on a sphere object that detects the hit by the laser ( on keypad 2 in the main demo, )

    is there a way to distinguish on the recieving object which of the 10 weapons have hit it, say i have 10 weapons on keys 1 to 0, and i want a different thing to happen depending upon which weapon is curently hitting the sphere, is there something in the send message that i can retrieve to check which weapon is hitting the sphere

    thanks
     
  4. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    If you're using ArcReactorHit message from Launcher, it provides ArcReactorHitInfo class, which contains launcher that sent this message along with RayInfo class that contains ray information. Using this you can correlate hit to weapon.
     
  5. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    could you please show me a simple code to do this as i do not understand what to write to retrieve that from the ArcReactorHtInfo class, i got it to recieve the ArcReactorHitIfo hit but do i just put ArcReactorHitInfo Launcher as when i try it it just gives an error in the console
     
  6. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    Code (CSharp):
    1. public void ArcReactorHit(ArcReactorHitInfo hit)
    2. {
    3.      // myLauncher is predefined launcher
    4.       if (hit.launcher == myLauncher)
    5.       {
    6.             //do something
    7.       }
    8. }
     
    Last edited: Apr 9, 2019
  7. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    thank you, now i can see it in code i understand it
     
  8. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    No problem. Also sorry, there was a mistake in previous example - correct event for you would be ArcReactorHit, not ArcReactorReflection.
     
  9. KamiKaze425

    KamiKaze425

    Joined:
    Nov 20, 2012
    Posts:
    207
    I'm getting an error about:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. ArcReactor_Arc.Initialize () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:1169)
    3. ArcReactor_Launcher.LateUpdate () (at Assets/ArcReactor/Scripts/ArcReactor_Launcher.cs:586)
    Which refers to this in Initialize:
    Code (CSharp):
    1. lrends[n].positionCount = vertexCount[n];
    Any ideas? Thanks
     
  10. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    Most likely linerenderers are not initialized or destroyed for some reason. Can you provide more information? When it happens, what's your setup etc. You can use support email for that.
     
  11. KamiKaze425

    KamiKaze425

    Joined:
    Nov 20, 2012
    Posts:
    207
    It is a VR game. The laser launcher follows the position of the player avatar's hand using FixedUpdate (I could not make it a child of the hand because of how VRIK updates the positions of the joints). Attached is an image of the settings. I only showed the first element even though there are 3. I had the same problem when I had only the first element.

    I also get an error with SetFlares() even though my flares are disabled. I just commented out the SetFlares() method to remove that one.
     

    Attached Files:

  12. MakeGames2020

    MakeGames2020

    Joined:
    Nov 14, 2014
    Posts:
    14
    Hi i get these errors when generating a ray even when just putting a fresh "ArcReactor_Arc" script on a empty object. The ray still generate without problems as far as I can so not sure if this is an issue or not. I recently switched over to the LWRP so not sure if this has anything to do with this.

    IndexOutOfRangeException: Index was outside the bounds of the array.
    ArcReactor_Arc.CalculateShape () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:689)
    ArcReactor_Arc.Start () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:1356)

    IndexOutOfRangeException: Index was outside the bounds of the array.
    ArcReactor_Arc.CalculateShape () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:689)
    ArcReactor_Arc.LateUpdate () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:1561)

    NullReferenceException: Object reference not set to an instance of an object
    ArcReactor_Arc.LateUpdate () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:1729)
     

    Attached Files:

  13. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    Hello.

    LWRP probably has nothing to do with it, please check your ShapePoints and ShapeTransforms arrays, and Particles options - make sure there's prefab placed there if particles are enabled.
     
  14. MakeGames2020

    MakeGames2020

    Joined:
    Nov 14, 2014
    Posts:
    14
    Hi I disabled the Emissions and that did stop the last error being generated which was generating the most amount but still getting the other 2 errors. I have transforms in place and the shape points set to zero. Ive included an image of my set up.
     

    Attached Files:

  15. firepitlong1

    firepitlong1

    Joined:
    Oct 19, 2019
    Posts:
    1
    Hi I was wondering if I could get some performance guidance from you. I am currently just using basic lines no lights, no emissions just as basic of a line I can get. From the image below once I start to generate more than 30 I start to get frame drops. Is there basic things I can do to improve performance? The pool manager doesn't seem to make any difference. Also wondering how I can use code to change value like color and fade points.

    Edit: Also just noticed something I might have been doing wrong. Segment length i was setting to 1 because I thought thats how many segments it would need, would increasing this to reduce the segments increase performance? Most of my lines are just straight so they would only need to be a single segment.
     

    Attached Files:

    Last edited: Oct 20, 2019
  16. jammer42777

    jammer42777

    Joined:
    Apr 21, 2014
    Posts:
    116
    I am wondering, are there any plans of implementing this in HDRP?
    I will need lasers for my game.

    Thank you!
    --Joshua
     
  17. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    No for iterations of current version, although ArcReactor 2.0 is planned as new product based on ECS and it will support different rendering pipelines.
     
    Last edited: Feb 14, 2020
  18. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    That's awesome, needed it today for a small prototype I thought I'd try with the new Victorian Interior asset:

    hunt.jpg

    Maybe an additional nice effect is to have some kind of charcoal along the hit positions. But that could turn out tricky because one would have to interpolate inbetween the hit positions, raycast and attach a trail renderer there. Unless someone has a better idea. Either way, here's the code I used for firing:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. /// <summary>
    4. /// Fire a proton beam on left mouse button click and ease out when player releases the mouse button
    5. /// </summary>
    6. public class FireProtonBeam : MonoBehaviour
    7. {
    8.     public ArcReactor_Launcher launcher;
    9.  
    10.     void Start()
    11.     {
    12.     }
    13.  
    14.     void Update()
    15.     {
    16.         if (Input.GetMouseButtonDown(0) && launcher.Rays.Count == 0)
    17.         {
    18.             launcher.LaunchRay();
    19.         }
    20.  
    21.         if (Input.GetMouseButtonUp(0))
    22.         {
    23.             foreach (ArcReactor_Launcher.RayInfo ray in launcher.Rays)
    24.             {
    25.                 ray.arc.playBackward = true;
    26.                 ray.arc.freeze = false;
    27.             }
    28.         }
    29.     }
    30. }
    and CatsPawGames' hit detector for rays

    Code (CSharp):
    1. using UnityEngine;
    2. using static ArcReactor_Launcher;
    3.  
    4. /// <summary>
    5. /// Spawn particles at hit position
    6. /// </summary>
    7. [RequireComponent(typeof(ArcReactor_Launcher))]
    8. public class ProtonBeamHitEffect : MonoBehaviour
    9. {
    10.     private ArcReactor_Launcher launcher;
    11.  
    12.     /// <summary>
    13.     /// The prefab to be spawned at the hit position
    14.     /// </summary>
    15.     public GameObject hitEffectPrefab;
    16.  
    17.     /// <summary>
    18.     /// Maximum amount of time until the spawned gameobject is destroyed
    19.     /// </summary>
    20.     public float hitEffectDuration = 3f;
    21.  
    22.     void Start()
    23.     {
    24.         launcher = GetComponent<ArcReactor_Launcher>();
    25.     }
    26.  
    27.     void Update()
    28.     {
    29.         if (launcher.Rays != null && launcher.Rays.Count > 0)
    30.         {
    31.             RayInfo ray = launcher.Rays[0];
    32.             Vector3 lastPosition = ray.shape[ray.shape.Length - 1].position;
    33.  
    34.             GameObject go = Instantiate(hitEffectPrefab, lastPosition, Quaternion.identity);
    35.             Destroy(go, hitEffectDuration);
    36.         }
    37.     }
    38. }
    39.  
    I thought I'd share in case anyone else has use for it in a quick prototype :)

    The particles spawned at a hit are just the ones from Unity's Particle Pack. The beam is the ProtonPack_continuous that comes with Arc Reactor.

    beam 2.jpg
     
    Last edited: Sep 19, 2020
    cygnusprojects likes this.
  19. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    Video is always better :D



    @CatsPawGames What I'd like to have in case you extend the asset:

    * more control over the light which the rays send out for global illumination
    * a trail renderer where the arc hits. maybe dark / coal or also with glow
    * more examples. for one rays, for the other use cases like this
    * more control where the beam starts, it's currently still shifting around in the front
    * maybe some delay at the end point to achieve some kind of drag effect

    All in all great asset!
     
    cygnusprojects likes this.
  20. sclassing

    sclassing

    Joined:
    Feb 10, 2020
    Posts:
    2
    Hello,

    I just purchased the ArcReactor rays generator from the Unity asset store, and I'm having some issues getting it to work with my version of Unity. I'm on version 2020.3.17f1.907.

    When trying to run any of the demo scenes, I get 2 errors and 8 warnings. (details below)

    Can you confirm that this asset will run on version 2020.3.17f1.907 of Unity?

    Thanks,
    Steve

    ---

    The errors are as follows:

    Error #1
    Assets\ArcReactor\Demos\Scripts\Demo1\ArcReactorDemoPlayerMotor.cs(25,19): error CS1061: 'CharacterController' does not contain a definition for 'isGrounded' and no accessible extension method 'isGrounded' accepting a first argument of type 'CharacterController' could be found (are you missing a using directive or an assembly reference?)

    Error #2
    Assets\ArcReactor\Demos\Scripts\Demo1\ArcReactorDemoPlayerMotor.cs(34,15): error CS1061: 'CharacterController' does not contain a definition for 'Move' and no accessible extension method 'Move' accepting a first argument of type 'CharacterController' could be found (are you missing a using directive or an assembly reference?)

    The warnings are:

    Warning #1
    Lighting data asset ‘LightingData’ is incompatible with the current Unity version. Please use Generate Lighting to rebuild the lighting data. Realtime Global Illumination cannot be used until the lighting data is rebuilt.

    Warning #2
    Component at index 2 could not be loaded when loading game object 'Main Camera'. Removing it!
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
     
  21. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Well you could just delete the demo script or fix those errors. Namespace add or w/e.
    (HINT: YOU ALREADY HAVE A CLASS CALLED THAT?)

    EDIT: seems fine. I didn't even get any errors in 2020.3.12f1

    upload_2021-9-13_3-1-22.png
     
    Last edited: Sep 13, 2021
  22. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    Hello.
    As twobob already mention (thanks for being on top of it faster than me!), project should be converting to 2020.3 without any errors. Please try to redownload it from Asset Store into a fresh project and see if errors persist. Most likely, as twobob said, you already have CharacterController class redefining built-in class. If this doesn't help, please send me a message to support email.
     
    twobob likes this.
  23. sclassing

    sclassing

    Joined:
    Feb 10, 2020
    Posts:
    2
    I just imported into a clean project and everything is working fine. Sorry about that - I should have mentioned that I'm a complete noob as well. :)
     
  24. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    i have been away from unity for a while and just decided to pick up where i left off, i am trying to detect upon hit which launcher is hitting my object using the example code below, i am of course changing the name of the laucher to my own but am getting an error, error CS0103: The name `LaserLauncher' does not exist in the current context

    can anyone test the code below for me as also posted above near top of page 8 of this forum as it was me that asked for it before and i thought that it did work then

    thanks in advance

    Code (CSharp):
    1.     public void ArcReactorHit(ArcReactorHitInfo hit)
    2.     {
    3.          // myLauncher is predefined launcher
    4.           if (hit.launcher == myLauncher)
    5.           {
    6.                 //do something
    7.           }
    8.     }
    9.  
     
  25. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    this is not making any sense, if i put
    Debug.Log(hit.launcher); the console displys which launcher has hit but if i try
    1. if (hit.launcher == LaserLauncher)
    2. {
    3. Debug.Log(hit.launcher);
    4. }
    if just gives error CS0103: The name `LaserLauncher' does not exist in the current context, how do i define the name LaserLauncher into my script i have tried
    GameObject LaserLauncher; but it still wont work, what the hell am i missing here???
     
    Last edited: Jan 2, 2022
  26. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Total guess... you don't have scope to the LaserLauncher within that method/test/tranche
    Please post the instantiation code.
     
  27. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    all the instantiation code is as default and works, i just need to get the name of the launcher when it hits an object so i can do different things depending on which launcher is fired, what i posted in previous post is posted further up page 8 of this thread as posted by the author of the asset, i have used it as described bt he says to predefine the launcher, what does it mean as the debug will show the name of launcher but i can not use the line of code he suggested if (hit.launcher == LaserLauncher) it does not get the name of the launcher?

    the code in previous post is atached to the recieving object, which needs to know which launcher has hit it.
     
  28. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    dude. in that time you could have just posted it.
    if (hit.launcher.gameObject.name == "SOMENAME")

    then
     
  29. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058

    Fwiw. "is as default and works" if it worked like you wanted you wouldn't be here.
    I have no idea what the defaults ARE which is why I asked to see it. Anyway, you should have your code now.
     
  30. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Is this asset working with HDRP ?
     
  31. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    thank you, not sure why catspawgames gave me the wrong code above, but now working.
     
  32. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    getting this error when using any of the launchers that have stick as the end point, after a while of firing the weapon the following red error happens and some of the weapon is then left stuck in the game, can this be fixed?

    IndexOutOfRangeException: Array index is out of range.
    ArcReactor_Arc.FillResultingShape () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:454)
    ArcReactor_Arc.CalculateShape () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:611)
    ArcReactor_Arc.LateUpdate () (at Assets/ArcReactor/Scripts/ArcReactor_Arc.cs:1564)
     
  33. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058

    It wasn't "wrong". It just tested for something you didn't want.
     
  34. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058

    I don't know if this is particularly maintained anymore (no disrespect intended to dev, just literally don't know)

    Easiest thing to do it simply look on LINE 454 of Assets/ArcReactor/Scripts/ArcReactor_Arc.cs and see for yourself why the array goes out of range.

    From my cursory glance it appears either of these arrays is being pumped AFTER it has been emptied or remade with less nodes resultingShape.position = shapePoints; (It's a guess, I didn't test)

    You might try:

    upload_2022-1-3_19-28-50.png

    In the event of just wanting it to "go away"
     
    Last edited: Jan 3, 2022
  35. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Highly doubtful. OOTB. and would require shader knowledge to port "completely". one would imagine looking at the custom shaders in SHADERS. You could probably fudge something together with other materials/shaders. Have not tried.
     
  36. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    does anyone know how i can get the launcher to send message to object if i have the end behaviour set to immobile as this would stop me getting the array error that i get when i use stick as end behaviour, i have trie to get it working, the laser detects the hit as it displays the hit particle at the beam end but it wont send the message to the hit object, it works ok if end behaviour is set to follow raycast but i need it set to immobile. is this possible

    thanks in advance
     
  37. tabulatouch

    tabulatouch

    Joined:
    Mar 12, 2015
    Posts:
    22
    Hello,
    How do you suggest ArcReactor can be used to make a snake-like game? So that the head movement and tail length are always tied with an arbitrary number of points?