Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Stretch to end" for CreateGameObjects
#1
Hi, I want the player to be able to create walls by drawing splines. The wall spline must consist of many separate GameObjects because each GO detects collision for valid placement:

[Image: doGNvIs.gif]

There's two issues I could use some help with:

  1. I want to be able to deform the GO's, especially so they can occupy the entire length of the spline, like the "stretch to end" feature of Deform Mesh. It is easy to deform the meshes (thanks Curvy 8), but the GameObjects must also scale so that their collision detection matches the size of their mesh.
  2. At the end of the gif, you can see the red (invalid) walls flickering randomly. I assume that the object pooler is switching the Gameobjects around as I resize the spline.

I wanted to ask around for some suggestions for strategies to address these. I am still learning to use Curvy, and I get the feeling that I am missing some more elegant ways than what I can imagine with my current knowledge.

Thanks in advance.
Reply
#2
Hi

About issue n°2: yes, your assumption is right. You can make your pooled game objects implement the IPoolable interface. By doing so, you can make your pooled objects execute custom code before and after pooling. You can clear the valid/invalid state in these methods.

I will come back to you soon about issue n°1

Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
About issue 1: The Deform Mesh module produces V(irtual) Meshes that, connected to a Create Mesh module, will create a game object containing the mesh, and if the option is set, will also produce the correct associated mesh collider. Have you tried using the Deform Mesh module for your wall? Since the wall is a straight line, there should not be any deformation other than the stretching. If you already have tried this solution and it doesn't work, please send me a reproduction case and I will look into it.
Thanks and have a nice day
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
Quote:About issue n°2: yes, your assumption is right. You can make your pooled game objects implement the IPoolable interface. By doing so, you can make your pooled objects execute custom code before and after pooling. You can clear the valid/invalid state in these methods.
Oh, perfect, thank you.

(05-30-2022, 03:16 AM)_Aka_ Wrote: About issue 1: The Deform Mesh module produces V(irtual) Meshes that, connected to a Create Mesh module, will create a game object containing the mesh, and if the option is set, will also produce the correct associated mesh collider. Have you tried using the Deform Mesh module for your wall? Since the wall is a straight line, there should not be any deformation other than the stretching. If you already have tried this solution and it doesn't work, please send me a reproduction case and I will look into it.
Thanks and have a nice day
Yeah, I tried this and it should work if I can add a prefab to each of the CreateMesh output Gameobjects. I think this is probably the correct approach, but would require a bit of reconfiguring of my Monobehaviors.

I did also try a different approach that would be easier, but it didn't work as I expected. I used CreateGameobject and tried modifying the scale of the input gameobject in order to stretch them. The Gameobject did scale, but the volume spots for their placement did not move, so I guess the input Gameobject's bounds did not scale. Are the bounds supposed to scale with the Gameobject?
See:
https://imgur.com/a/1IGEfli
Reply
#5
Sorry for taking longer than usual in answering you. Will answer you in the next 24 hours.
Is it possible for you to send me a simple reproduction case?
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
Hi again

(05-30-2022, 06:07 PM)Anubis132 Wrote: Are the bounds supposed to scale with the Gameobject?

It is supposed to be. I attached a modified version of the asteroid example scene. You can see that changing the scale of the input asteroid updates the spots properly. Please take a look at that scene, and if you find out that you configured something, then great, otherwise, please send me the reproduction case so I check if this is a bug on my side.

I hope this helped

Have a nice day


Attached Files
.unity   28_AsteroidBelt.unity (Size: 52.88 KB / Downloads: 1)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
Quote:Please take a look at that scene, and if you find out that you configured something[...]

Ah, thanks, I see what happened. It's because I have a 90 degree rotation about Y in the Input GameObjects properties. The GameObject stretches along the spline when I scale it in X, but the spots only move when I scale it in Z because they always use the gameobject's pre-rotation bounds.
[Image: 4okwKeY.png]
This also affects Deform Mesh, so I will need to modify the input bounds based on the rotation in either case.
Reply
#8
Based on the above, I tried to modify the input bounds.
Code:
                    var volumeSpots= m_splineGameobject.GetComponentInChildren<BuildVolumeSpots>();
                    var spotBounds = volumeSpots.Input[1].GetData<CGBounds>().Bounds;

                    spotBounds.size = new Vector3(10f, 10f, 10f);
                    volumeSpots.Refresh();
Even with this basic test case, the volume spots are still placed based on the original input Gameobject's Z bounds. What's the correct way to modify the volume spots input bounds?
Reply
#9
Hi
Indeed, Volume Spots does not consider the GO's rotation you set. Here is a quick fix for this:
in CGData.cs, go to the CGGameObject.RecalculateBounds method (line 2504) and replace the following
Code:
bounds.size = new Vector3(
                    rotationlessBoundsSize.x * Scale.x,
                    rotationlessBoundsSize.y * Scale.y,
                    rotationlessBoundsSize.z * Scale.z);
with this
Code:
bounds.size = Quaternion.Euler(Rotate) * new Vector3(
                    rotationlessBoundsSize.x * Scale.x,
                    rotationlessBoundsSize.y * Scale.y,
                    rotationlessBoundsSize.z * Scale.z);
Let me know if this fixed your issue.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#10
(06-05-2022, 05:04 PM)_Aka_ Wrote: Let me know if this fixed your issue.
Have a nice day

Yes it did, although it needed a small modification. The rotation can produce a vector with negative components, which leads to bad behavior. Using the absolute values worked:

Code:
                Vector3 vec = Quaternion.Euler(Rotate) * new Vector3(
                                    rotationlessBoundsSize.x * Scale.x,
                                    rotationlessBoundsSize.y * Scale.y,
                                    rotationlessBoundsSize.z * Scale.z);
                vec.x = Mathf.Abs(vec.x);
                vec.y = Mathf.Abs(vec.y);
                vec.z = Mathf.Abs(vec.z);
                bounds.size = vec;

Thanks for the help.
Reply


Forum Jump: