- Home /
Creating Box Collider On Specific Terrain Textures
Hello,
I know how to get the information of which textures etc are in the Terrain, however for my game purposes I am trying to figure out how to create a box collider for where there is "dirt" for example as a texture as long as there is dirt I do not want to allow my character to move towards it, therefore need to create a collider about 10 units long in Y where the "dirt" texture exists... Any ways of getting this done effectively ?
In the meanwhile I will be brainstorming as well.
Thanks a lot
EDIT: This will be a phone game, therefore I'm not sure raycast is the best way, perhaps a box collider of where the character is and reads the texture its on?
Answer by whydoidoit · Feb 13, 2014 at 01:24 AM
I'd suggest using a raycast in the direction of movement and then work out what is on the terrain in that direction by using the RaycastHit textureCoord to get access to the splat map at the location intersected. You would then look to see how much of the "dirt channel" was present to limit movement.
Thanks for the answer, however I'm not sure that will work with a raycast - this is for a phone game
Why would a raycast not work on a phone? If your talking about performance, one raycast is nothing. Even if you needed 3 or 4, still nothing to be worried about.
It would end up being much faster than all of the colliders you would create to cover the different areas that had your dirt.
So how do i go on about creating a raycast shooting out of a "cube" placed in front of my character, checking about 0.2 meters ahead of where he'll be stepping, to find out what texture is co$$anonymous$$g up, and if its "dirt" to prevent him from moving forward...??
Your answer
Follow this Question
Related Questions
Create Terrain in other Software 1 Answer
Specific Texture collision 1 Answer
Disabling colliders in Terrain Trees? 1 Answer
How can I delete grass texture from Terrain 2 Answers
Paint terrain texture with scripting 1 Answer