x


Making water impassible

Just as the title suggests... is there a way to make it so that a character cannot walk in to or on to water in my scene?

I just want to make the areas where I have water off-limits.

more ▼

asked Feb 25 '10 at 04:16 PM

PrimeDerektive gravatar image

PrimeDerektive
3.1k 57 64 84

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

If you're using the physics engine for general movement and control of the objects in your scene, you might want to make some invisible walls around your water areas.

Create the wall meshes as normal in your 3D app, then just make sure they have a Mesh Collider attached, marked as static, and disable the renderer component - making them invisible.

more ▼

answered Feb 25 '10 at 04:30 PM

duck gravatar image

duck ♦♦
40.9k 92 148 415

Ugh, I was afraid of that answer, haha. I'm not much of a 3d guy, trying to do this exclusively with purchased assets and the build in editors :)

I guess I'll just have to flatten some cubes into walls and position them accordingly, but thats going to take FOREVER!

Feb 25 '10 at 04:33 PM PrimeDerektive

Depending on how your scene is set up, there may be a way to achieve this by doing some kind of 2d "scan" of your scene which detects which areas are water or not, and then dynamically building a collision mesh to fit. No small task though, but if you're more a coder than an 3d artists, this route might be preferable.

Feb 26 '10 at 10:31 AM duck ♦♦
(comments are locked)
10|3000 characters needed characters left

I'm going to play with your requirements a bit here, but this should be a LOT easier to implement. I'm a coder, so every time I hear "make a mesh in your 3d program" I look for a workaround...

Assuming that your water is all at a certain height, and the player never needs to go below that depth for any reason: Create a box collider the size of your bodies of water. Set it to Is Trigger. Lower it to the appropriate height.

Each frame your player is on the ground, check to see if he has a collision event with one of these water colliders. If he does not, remember his position. If he does, go back to that position and set his velocity to 0.

This approach should require little time to implement, as long as you dont frequently need to go below water level right next to the water.

more ▼

answered Feb 27 '10 at 05:44 AM

Kethis Celebes gravatar image

Kethis Celebes
149 8 9 18

Thanks! I thought about a solution similar to this, but I didn't think it would work because I didn't think to record my previous frame's position. Brilliantly simple!

And yes, my water level is the lowest reachable terrain on my map, so that should work perfectly :)

Mar 05 '10 at 02:49 PM PrimeDerektive
(comments are locked)
10|3000 characters needed characters left

use triggers. create box colliders and put them around your water surface. or create a big sphere collider and put it inside your water and make it bigger than your water surface. then in OnTriggerEnter of those triggers don't allow the player to go inside triggers.

more ▼

answered Feb 27 '10 at 06:44 AM

Ashkan_gc gravatar image

Ashkan_gc
9k 33 56 117

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2483
x299

asked: Feb 25 '10 at 04:16 PM

Seen: 2180 times

Last Updated: Feb 25 '10 at 04:16 PM