Texture collision?

Blitz3D Forums/Blitz3D Beginners Area/Texture collision?

Guy Fawkes(Posted 2010) [#1]
I need to know how to detect whether or not my player collides w/ the grass, ground, water, etc.

and please don't tell me to use a 2nd object because i already made my level.


Ross C(Posted 2010) [#2]
Your best for grass is to do some of texture or grid look up. it all depends on how your level is built. is it geometric grass or simply a texture. is your water a seperate entity?


Oiduts Studios(Posted 2010) [#3]
What I do is divide the completed terrain into sections; grass,rocks,sand, etc. Then use collisions to determine the surface type. But since you said you didn't want to mess with the level you could do what Ross C is saying and check for distance on grass entities or a water plane. Or have some kind of grid system.


Guy Fawkes(Posted 2010) [#4]
my grass is simply a texture


Oiduts Studios(Posted 2010) [#5]
I don't know how much the processor would like this but...you could create pivot types and lay them out on your terrain and check distance on them. The problem with this is you would have to individually tell which ones are grass,dirt,sand,etc. :)


Ross C(Posted 2010) [#6]
There is also a function in the archives, that will return the picked U and picked V of a pick opertion, so you can get where abouts on a texture, the pick hit.


Oiduts Studios(Posted 2010) [#7]
I would love to get my hands on that...


Warner(Posted 2010) [#8]
Search for: "pickedu site:blitzbasic.com" in Google.


Ross C(Posted 2010) [#9]
It's in the Misc Effects catagorie of the code archives, for 3d.

http://www.blitzbasic.com/codearcs/codearcs.php?code=515

Super handy piece of code.


jfk EO-11110(Posted 2010) [#10]
What I did for the footsteps procedure in my game engine is this:

first all surfaces of the level map mesh are investigated. See the SaveB3D Code in the archive on how to determine the texture filename of a certain surface (GetSurface,GetSurfaceBrush,GetBrushTexture, GetTextureName(?) etc. ). Once you have stored all the names of those textures together with the surface handles that are using them, it will be pretty simple to do a LinePick versus the ground (need that for many other things anyway) and then check the PickedSurface(), and, depending on the texture under your players feet, play a certain footstep sound, eg. Metal Floor: Klong Klong...
This allows to use various textures and assign an individual sound to each one on them. Not sure if this is what you need.

I have a file named "footsteps.info" or so, containing something like this:

grass.jpg
feet_on_grass.wav
woodenfloor.bmp
feet_on_wood.wav
gravel.jpg
feet_on_gravel.wav

There is also a default sound for the footsteps, used by all ground textures that are not defined in "footsteps.info". This way it's not so much work fot the level designer.

Colliding with water may be a bit more complicated, because you want to make a diffrence between touching the water with the players feet only, and when the player is completely under water. So this may be more a "is player inside a water xyz box? and if so, only his feet or the entire body?" thing. ALso because of exceptional gravity modes when in or under water.

BTW GetSurfaceBrush and GetBrushTexture will create a new copy of the examined Brush and Texture. You need them only until you have determined the texturefile that is used by the surface in question. After that you HAVE to free those again to prevent a Memory Leak.


D4NM4N(Posted 2010) [#11]
use a second mesh surface and....

oh

use a downward render to a 10x10 pixel image buffer, find the average rgb from the visible and test its rgb alliegence. If its in the green range then its grass, if its grey its stone, if its brown its wood etc.


wmaass(Posted 2010) [#12]
ARRGH, I forget who it was that made a function for me that allowed me to get the texture of the surface I was colliding with. Worked wonders for my golf project. I'll see if I can find it.


Oiduts Studios(Posted 2010) [#13]
D4NM4N's solution is crazy awesome, did u just make that up or do you know that from experience?


MadJack(Posted 2010) [#14]
Suggest you pause the programme periodically and ask the player what his avatar's standing on. A dropdown list should do the trick.
The player won't mind.


Oiduts Studios(Posted 2010) [#15]
^^HAHAHAHHAHHAHAHHAHAHHAAHAHA