Findig the layer my player is standing on?
perhaps this is not the right place, but you seem to be very good with supporting people and I thought maybe you happen to know a solution.
I'm using your tool to basically create different types of ground for my player to walk on. On certain key strokes I need to perform actions according to the layer the player is currently standing on. I've been battling with this problem for a while now, no luck so far on finding anything. Well anyway, I'm looking for a way to dynamically get the layer my player is in contact with and I guess getting it out there to a larger audience might improve my chances. :) Feel free to delete if this is too far out of your scope or just not suitable for this forum.
Ps.: I've been helping myself by simply finding the closest edge and determining the layer that way. This breaks down since I can't place the vertices of different layers exactly on top of one another and so they overlap which breaks the method. Can you perhaps think of a way to do it by allowing me to snap vertices of different layers?
Baroni last edited by
the easiest way would be to give your ground a collider, then raycast from the player downwards (ignoring the player layer). If the ray hits something with the assigned layer or tag, you could get the object (or its layer/tag) and determine what should happen for each case.
but wouldn't that still leave me with the problem of getting the layer itself?
I'm using Extensions just so I don't have to break up the ground into different objects but so I can just do it all with one single terrain object.
If I raycast down I would only hit the terrain which still leaves me without a method to determine the NavMesh layer.
I apologize if I misunderstood and thank you for responding :)
Edit: I still think that just getting the different layers to allign exactly (snap vertices to each other) would be the easisest solution since then my current
hack of finding the closests layer edge would presumably work in all cases. Is there maybe a setting I've missed so I don't have to overlap them to ensure contact?
Edit 2: I just realized that the different layers are objects themselves, so I can probably use that after all :D I'll be back...
quick update: I did get it to work as per my second edit to my last post :)
Just had to give the layers some mesh colliders, raycast down and store the GameObject as a string.
Works like a charm and much better than my previous hack.
Thanks a lot for the idea, I was going insane trying to figure this one out :D
Baroni last edited by
Good to know it's working out for you, you're welcome :)