#JJfriends chunk thingy forest

1 messages · Page 1 of 1 (latest)

sick inlet
#

ok

#

@sleek hedge

sleek hedge
#

So what's confusing now

sick inlet
#

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

sleek hedge
#

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

sick inlet
sleek hedge
sick inlet
#

like this?

#

cus the script is already attached to the mesh

sleek hedge
#

transform.position.z not y

sick inlet
#

@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

sleek hedge
#

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

sleek hedge
sick inlet
#

nothing spawned

#

only 1 cube at y 1000

sick inlet
sleek hedge
#

After the raycast check, do point.y = hit.point.y

sick inlet
#

outside the if statement?

sleek hedge
#

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

sick inlet
#

alright it didn't spawn anything

sleek hedge
#

Then transform.position is maybe not the correct pivot

#

You should debug the raycast

sick inlet
#

shoudln't it still spawn tho?

#

alr

sleek hedge
#

Debug.DrawRay(point, Vector3.down * 5000, Color.yellow, 10f);

#

Before the raycast.

sleek hedge
sick inlet
#

holy fuck

sleek hedge
#

Now you see your rays, it's up to you to fix the correct offsets etc.

sick inlet
#

its still making a collison tho

#

so shouldn't it still spawn?

sleek hedge
sick inlet
#

which is the condition for it to spawn

#

am i missing smth

#

lol

sleek hedge
#

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

sick inlet
#

question abt here

sleek hedge
#

Bruh, you didn't change that?

sick inlet
#

wait

#

dang

#

im stupid

sleek hedge
sick inlet
#

sorryyy

#

also now the pos for the lines are correct

#

but no red lines

#

so it didnt hit

sleek hedge
#

If you rotate the view, are they actually going thru the mesh?

sick inlet
#

they are

sleek hedge
#

Does it have a proper mesh collider?

sick inlet
sleek hedge
#

Test if a normal rigidbody goes thru it or collides with it

sick inlet
#

it does

#

the player collides

sleek hedge
#

Can you screenshot your current code again?

sick inlet
sleek hedge
#

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

sick inlet
#

nothing

#

i tried changing it to 100

sleek hedge
#

Your terrain is not on the Ignore Raycast layer is it? 😅

#

I need to go, already spent more than an hour here lol

sick inlet
#

nope

sleek hedge
#

Hope you find whats wrong or someone else can help

sick inlet
#

ah no worries its fine

sleek hedge
#

I can check it out later

sick inlet
#

tysmm

#

for everything

sick inlet
#

@sleek hedge if i changed my code like this

#

all the raycasts redirect to the same point

sleek hedge
#

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

sick inlet
#

cus it detects for some reason when i don't invert it

sleek hedge
#

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)

sick inlet
#

oh

#

welp

sick inlet
#

@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;

    }```