#JJfriends chunk thingy forest
1 messages · Page 1 of 1 (latest)
So what's confusing now
alright so basically the chunk has a different position right so I need the points to be only in that poisiton for every new chunk
basically it needs to be within the chunk
Yeah just add that chunk's position to the tree's position
Might need to subtract half of the size from it or something, I don't know where your terrain's pivot is
do i add it too here
No you can just add it to the var point you create in the loop
transform.position.z not y
@sleek hedge alright so the raycast didn't rly hit so it kinda just spawned in the same y coord
is it because im using mesh colliders or something
this is what it currently looks like
Don't remove the if check from the raycast
Actually just do
if (!Physics.Raycast(point, Vector3.down, out hit))
{
coninue;
}
So that it skips that position if the ray didn't hit anything
As long as your mesh colliders are the same shape as your terrain, its fine
Did you do this?
Now you aren't using hit.point anymore...
After the raycast check, do point.y = hit.point.y
outside the if statement?
Yeah
Because if the code passes that if statement, you have a hit.
Otherwise you continue which means skip the current iteration of the loop
I added the 10f so it stays 10 seconds @sick inlet
holy fuck
Now you see your rays, it's up to you to fix the correct offsets etc.
How do you know?
the ray touchs the mesh with a collider on it
which is the condition for it to spawn
am i missing smth
lol
Alright lets make the ray debug a bit better.
Put this inside the if(!Physics.Raycast(... block:
Debug.DrawRay(point, Vector3.down * 5000f, Color.green, 10f); // Draw miss```
And after that block, outside of it:
```cs
Debug.DrawLine(point, hit.point, Color.red, 10f); // Draw hit```
And remove the previous Debug.DrawRay
Bruh, you didn't change that?
......
sorryyy
also now the pos for the lines are correct
but no red lines
so it didnt hit
If you rotate the view, are they actually going thru the mesh?
they are
Does it have a proper mesh collider?
Test if a normal rigidbody goes thru it or collides with it
Can you screenshot your current code again?
w
Not sure what's wrong yet, really
For starters, try changing the 1000 to something lower, maybe 100
You are almost done, but for some reason the raycast won't detect your mesh collider
Maybe it has too many vertices or something... don't know
Your terrain is not on the Ignore Raycast layer is it? 😅
I need to go, already spent more than an hour here lol
nope
Hope you find whats wrong or someone else can help
ah no worries its fine
I can check it out later
@sleek hedge if i changed my code like this
all the raycasts redirect to the same point
It was !Physics.Raycast and now you inverted it..
Just keep the !Physics.Raycast and continue there like it was before.
And put that if(hit.collider... check after the if(!Physics.Raycast... and continue
I don't know why you changed the structure so much and broke it completely
i changed it back im just experimenting anything to see if i can get it to work
cus it detects for some reason when i don't invert it
Yeah that's fine, it's just that the logic there doesn't really make sense
Because you are currently drawing the misses if you hit 🤔
And drawing the hits if you didn't even hit.
(That's why they all point to the same position: because the default hit.point is zero)
@sleek hedge I did what you told me about the shared mesh but it still doesn't raycast
this.coord = coord;
this.detailLevels = detailLevels;
this.colliderLODIndex = colliderLODIndex;
this.heightMapSettings = heightMapSettings;
this.meshSettings = meshSettings;
this.viewer = viewer;
sampleCentre = coord * meshSettings.meshWorldSize / meshSettings.meshScale;
Vector2 position = coord * meshSettings.meshWorldSize ;
bounds = new Bounds(position,Vector2.one * meshSettings.meshWorldSize );
meshObject = new GameObject("Terrain Chunk");
meshRenderer = meshObject.AddComponent<MeshRenderer>();
meshFilter = meshObject.AddComponent<MeshFilter>();
meshFilter.mesh = myNewMesh;
meshCollider = meshObject.AddComponent<MeshCollider>();
meshCollider.sharedMesh = myNewMesh;
meshRenderer.material = material;
treePos.Add(meshObject.transform.position);
treeObject = new GameObject("Tree Chunk");
meshTree = treeObject.AddComponent<TreeGen>();
treeObject.transform.position = new Vector3(position.x, 10, position.y);
meshObject.transform.position = new Vector3(position.x, 0,position.y);
meshObject.transform.parent = parent;
SetVisible(false);
lodMeshes = new LODMesh[detailLevels.Length];
for (int i = 0; i < detailLevels.Length; i++) {
lodMeshes[i] = new LODMesh(detailLevels[i].lod);
lodMeshes[i].updateCallback += UpdateTerrainChunk;
if (i == colliderLODIndex) {
lodMeshes[i].updateCallback += UpdateCollisionMesh;
}
}
maxViewDst = detailLevels [detailLevels.Length - 1].visibleDstThreshold;
}```