Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add Volume to the Volume Controller Dynamically
#1
I am ultimately trying to add a VolumeController for the Infinite Track scenario so that I can have an Infinite Track but also move the controller side to side. the issue I'm having is setting the "Volume" property of the VolumeController to the Volume of the Dynamically created generator's shape extrusion. How to I access the Volume property of the generated Shape Extrusion within the Script?

Thank you-
Reply
#2
Ok, so I figured out how to dynamically set the Volume Controllers Volume to the Shape Extrusion's Volume. However, can someone give me a hint on how I would update the Volume to each section of the infinite track as the object moves to it?
Reply
#3
Hi,
In the Infinite Track scene, you have multiple Curvy Generators that each generates the mesh of a section of the track. The section's start and end is defined by the StartCp and EndCp of the Input Spline Path of the generator.

Code:
           //First, we find the index of the Control Point starting the segment the ship is on
           int nearestSegmentStartIndex;
           {
               float nearestSegmentF;
               CurvySplineSegment nearestSegmentStart;
               Vector3 nearestPoint;
               TrackSpline.GetNearestPointTF(Controller.transform.position, out nearestPoint, out nearestSegmentStart, out nearestSegmentF);
               nearestSegmentStartIndex = TrackSpline.ControlPointsList.IndexOf(nearestSegmentStart);
           }

           //Then, we find which CurvyGenerator is generating the mesh that includes the found Control Point
           foreach (CurvyGenerator curvyGenerator in mGenerators)
           {
               InputSplinePath inputSplinePath = curvyGenerator.FindModules<InputSplinePath>(true).Single();
               int startCpIndex = TrackSpline.ControlPointsList.IndexOf(inputSplinePath.StartCP);
               int endCpIndex = TrackSpline.ControlPointsList.IndexOf(inputSplinePath.EndCP);
               if (nearestSegmentStartIndex >= startCpIndex && nearestSegmentStartIndex < endCpIndex)
                   Debug.Log("The ship is on the mesh generated by " + curvyGenerator.name);
           }

I hope this helped
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#4
This does help a lot but I've run into another issue and I'm hoping you can help me with this. The code above works well and gets me the generator as the controller moves past it. I'm trying to also add a Volume Controller to this so I can move the ship side to side but also have an infinite track.

The infinite track uses the SplineController to trigger Track_OnControlPointReached event which I added the above code to so that we can change generators as we move past CP's

If I change the Controller on the InfiniteTrack to be a Volume Controller I lose the access to the CP's so I am not sure how to know where we are on the track in order to switch generators so I can move forward and side to side but only on one of the segments.

I tried modifying the InfiniteTrack to hold a variable for both a VolumeController and a SplineController but they seem to be conflicting somewhere. I feel like there is something I'm missing and I just can't figure out what it is.
Reply
#5
Hi,
I see two solutions:
1- Coding your own OnControlPointReached: The idea is that even if you don't use a SplineController anymore, nothing stops you from querying the spline with your ow code. In the code I sent you before, there is code that gives you the nearestSegmentStart. You can run this code each frame, and compare the result with the one of the previous frame. If the result is different, then execute the code you would normally execute in OnControlPointReached.
2- Not using OnControlPointReached: OnControlPointReached made sense when the controller was a SplineController. Maybe when using a VolumeController, alterantive logics can work as well. I haven't gave this a deep thinking, but it seems to me that triggering the generator change based on the controller's RealtivePosition instead of based on OnControlPointReached is a valid alternative logic.

PS: your message was duplicated in its middle. Maybe I missed part of it because of that. Let me know if I have missed something
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
(04-16-2019, 04:13 PM)_Aka_ Wrote: Hi,
I see two solutions:
1- Coding your own OnControlPointReached: The idea is that even if you don't use a SplineController anymore, nothing stops you from querying the spline with your ow code. In the code I sent you before, there is code that gives you the nearestSegmentStart. You can run this code each frame, and compare the result with the one of the previous frame. If the result is different, then execute the code you would normally execute in OnControlPointReached.
2- Not using OnControlPointReached: OnControlPointReached made sense when the controller was a SplineController. Maybe when using a VolumeController, alterantive logics can work as well. I haven't gave this a deep thinking, but it seems to me that triggering the generator change based on the controller's RealtivePosition instead of based on OnControlPointReached is a valid alternative logic.

PS: your message was duplicated in its middle. Maybe I missed part of it because of that. Let me know if I have missed something

I edited my post to remove the duplicate info. 

Your direction makes a lot of sense and I look forward to going home and trying to implement something that takes into account the relative position of the controller. while I'm not new to development I'm new to game development and unity so obvious concepts like this have been alluding me. I think this will actually get me to my goal. 

Thank you very much for your guidance. I'll let you know how it goes.
Reply
#7
Don't hesitate to ask if you have any other question.
Also, since you are new to Unity, I will share with you something that took me time and hair pulling to learn the hard way: the == operator of the UnityEngine.Object (from which MonoBehaviour inherits) can return true to the following statement "variable == null" even if "variable" is not null. More information about this here: https://docs.unity3d.com/ScriptReference...or_eq.html
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
I forgot to say something important:
In the code above, I wrote:
Code:
TrackSpline.GetNearestPointTF(Controller.transform.position, out nearestPoint, out nearestSegmentStart, out nearestSegmentF);
This is misleading, because the first parameter of GetNearestPointTF needs to be the position in the local frame of the spline. In my code it is the position in the global (world) frame. The correct could would be:
Code:
TrackSpline.GetNearestPointTF(TrackSpline.transform.InverseTransformPoint(Controller.transform.position), out nearestPoint, out nearestSegmentStart, out nearestSegmentF);
The first version of the code worked because TrackSpline had a default transform, i.e the same transform than the world's, so the transformation did nothing. If TrackSpline's transform is modified, then the first version of the code would stop working correctly.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#9
One quick question, I think I'm almost there...however when I dynamically switch the VolumeControllers Volume to the next generator in the list the controller's position gets bumped to whatever control point I was on on the new generator

For example if I'm on CP 4 on Generator 0 and I update the volume to Generator 1 the controller will jump to CP 8 which it the 4th CP on generator 1. I was looking through my code and don't see anywhere that I'm updating positions. Even if I manually switch the volume at runtime the controller jumps around.

Any ideas as to what may be causing this?
Reply
#10
The volume controller's position is tied to the volume, and not the spline. So if you don't update your position, which is let's say a relative position of 0.5, switching from volume A to B will move the controller from the middle of the volume A to the middle of volume B. So each time you switch volume, you will need to update the controller's Position too.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Spline Controller restart FlebusCroqus 2 598 05-16-2019, 07:35 PM
Last Post: FlebusCroqus
  Spline Controller Position Force Update ? UsernameHed 1 519 05-16-2019, 12:20 PM
Last Post: _Aka_
  Applying Centrifugal Force to Controller Mighty183 5 1,449 03-07-2019, 10:43 AM
Last Post: _Aka_
  Placing objects on volume Anthonyk 3 1,193 12-31-2018, 02:48 PM
Last Post: Anthonyk

Forum Jump: