how to collide with water type objects?

Blitz3D Forums/Blitz3D Programming/how to collide with water type objects?

D_Town_Tony(Posted 2004) [#1]
I have a plane that represents acid, when my character is in the acid I want his life to go down, I can't use collisions to detect it because I want him to go into the acid not sit on top of it, any ideas on a way to do this?


Stevie G(Posted 2004) [#2]
Make the plane pickable and then use linepick to check.


jhocking(Posted 2004) [#3]
You could use MeshesIntersect, although that command can be slow.


OrcSlayer(Posted 2004) [#4]
Well, if it's just a plane, make his life go down when his position is below the Y position of the acid (might need to add/subtract a little depending on your collision radius).


sswift(Posted 2004) [#5]
Look in the code archives for my polygon clipping system.

Set up planes that define a convex region containing the acid.

In other words, set up six planes if the acid is in a rectangular hole. Top of acid, bottom of hole, and 4 sides to hole.

Region could also be somewhat cylindrical with X number of sides. And it might even be able to be concave, but I won't guarantee that as I don't know if the agorithm can handle that properly.

Once you have done this, there is a function in the lib which tells you if a sphere is intersecting/inside the region defined by the planes. It will also tell you if any polygons are intersecting/inside the region, but a sphere test would be much faster and more than accurate enough.

Don't send me emails for support though! :-) Post here if you have questions.

The system also has a function to tell you the plane equation of a triangle, so if you can find one triangle of each side of your cube region you're in business.


fredborg(Posted 2004) [#6]
You could use the AreaCollision system by David Bird.

You can find it here: http://www.blitzbasic.com/codearcs/codearcs.php?code=316


sswift(Posted 2004) [#7]
Ps:

There are many other ways to do this.

One way would be to look down on the scene from above, and dtermine if the center of the player is inside the 2D region that the acid is in. Then dtermine the player's Y height, and if that matches the region between the top of the water and the bottom of the pool, then they're definitely inside the acid. Though you might have to fudge the heights a bit because their feet could be dipping in it while their center remains safely above it.

Another would be to make a polygon representign the surface of the water, and simulating the player with a vertical line segment. If one or both points of the vertical line segment are on the bottom side of the acid plane then they're in the acid... unless they're in a room under the acid, in which case you need to check that. And you still need to check that the points are in the 2d region that bounds the acid when looking down from above.

I suggest using my library though. It'll be totally accurate and there's lots of cool stuff you can do with it besides this.


sswift(Posted 2004) [#8]
Fred:
That limits you to rectangular regions that are aligned to the grid though. Just so he knows. He might not want his acid pit to be rectangular and/or aligned to the grid.


jfk EO-11110(Posted 2004) [#9]
It may be a useful compromise to limit the shapes to rectangular areas, aligned to the grid. This way you can set huge areas to be water and in the same time allow rectangular containers with say acid.

The reason why this is useful is it's gonna be very fast to check if the player is inside such a cube. A leveleditor can be used to define water zones by a simple scaled box. The engine can then determine min and max xyz of all water boxes at startup. This way it will take only a fragment of a milliseconds to check all water-boxes. Slow Linepicks are not neccessary, as well as MeshesINtersect, whoch would return zero if the player if completely inside a water object.

If you once know that the player jumped into the water, all you have to do is reducing gravity to almost zero, use some kind of filter etc.


cash(Posted 2004) [#10]
Not an expert by any means but could you not place another object below the plane and use that to have the player collide with and reudce the health, it would still mean the player would stop but give the effect it was below the plane.


sswift(Posted 2004) [#11]
jfk:
The method I outlined allows you to check against multiple bodies of water, and it extremely fast.

How fast? Well, if you imagine each polygon in a level is 10 of those spheres, I can test at least 3,000 polygons per frame, which means you could have 30,000 bodies of water tested against one sphere and not have any hiccups in framerate.


D_Town_Tony(Posted 2004) [#12]
Thanks guys, very helpful.
sswift-that method worked out great.


OrcSlayer(Posted 2006) [#13]
Sorry to bring up an ancient thread, but the point has come that this is something I need to be concerned about...Sswift, your method seems to be the best, but please, can you give me an example as to how to do it with your polyclip system?

I just spent a while browsing through your polyclip code and...I've got nothing.


Red Ocktober(Posted 2006) [#14]
actually... i think a lot of the ideas are great... but in this case, a bit overkill...

the suggestion Orc made above should work fine... just check the y position of the entity, or an offset from the y...

--Mike


OrcSlayer(Posted 2006) [#15]
That was ok for my original plan, which was to have one liquid plane per map...but now plans have changed and I need to be able to seperate liquid areas into rectangular zones...

I got the area collision by david bird working perfectly for what I need, but I'm a bit disturbed by the fact that the code isn't declared public domain...


Sledge(Posted 2006) [#16]
actually... i think a lot of the ideas are great... but in this case, a bit overkill...



I agree - welcome to over-engineering.com ;)

You can use Blitz collisions pretty much as normal - just make a child pivot that is sensitive to acid and try to position it at the player's feet each frame. If he's in acid it will register.