Hi everyone, I have been trying for a while to get a simple swimming mechanic to work and have been having a bunch of problems with it. First I made 3 states, one where the player is on land, one where the player is on the surface of the water and another where the player is beneath the surface. The idea is to make it similar to the mechanics in Spyro 2/The 3d Zelda games where you can simply stay on the surface, or hold the accelerate button and point down (or have a dive button), or jump off the water and land. What I also like about the idea of a Spyro 2 system is you can do a sort of “dolphin jump” where you jump out and back in the water (I think LoZ: Majora’s mask did this as well).
There are a few other things to consider, like how to adjust the way gravity is handled underwater. However at the moment I just want a basic state to state thing, the base blend file I will provide will have 3 states with the motion I am going for with each;
State 1 Land movement
State 2 Water Surface movement
State 3 Underwater movement
Water swimming test.blend (724 KB)
Not very impressive when it comes to movement, but as I said, it’s only basic.
I know state 2 in the blend file is a little weird looking, but it’s the only way I could think of that would keep the object on the surface without falling back down. If you have a better idea of how to do it then I would really like to hear it
The placeholder water is nothing more than a plane, now the real problem is that I want the underwater state to activate when the player is no longer contacting the surface and is beneath it, I tried using rays which would send a message to the player (didn’t work… at all), I tried using the radar sensor which would also send a message to the player(which works outside of the water, something I obviously don’t want). I would use collision if it wasn’t for the fact that I would likely face the same problem of it working outside of the water completely.
The main thing I need is for there to be a sort of “volume” cast beneath the water plane (btw I don’t plan on keeping the water a static plane in a future test, I would like to see how such a system would work with solarlune’s wave script, or using the ocean mod and applying shape key animations to it), this way I can use a message sensor under the water and it should (theoretically) work accurately. I imagine something like this could be useful for other underwater things.
If you guys could please help it would be greatly appreciated and I will definitely put this in the resource section if it works.
I thought of that, that might work with a plane, but I intend to use Solarlune’s wave script and if I make two waves over each other (with quite a few polygons on their own) that would not be an efficient way to handle it in the game engine. Thanks anyway
While previously working on a 3D platformer, I thought about using a domain object to define areas that are filled with water (basically just a cube or rough model that encompasses all underwater areas). You could theoretically line up the top face of this domain to match the water’s height.
Also, I’ve seen a physics collision type called “Sensor”. I haven’t looked into this, but I believe it behaves like “No Collision” so objects can still pass through it, but can be detected by the collision sensor. You could use this to determine if your character is underwater or not without using rays. I haven’t experimented with this, but you could give it a try. Good luck.
Not necessarily, I think he just wants the visible surface of the water to be a separate object from the calculated underwater areas. That’s why I suggested the water domain idea. This way you can have twisting underwater caves without having an unnecessary water surface above them.
@MC Studios, that’s not what I want at all, I want only one object (a plane in this case) for the water and have a ray at the -Z axis, the only problem is that it doesn’t work for some reason, the ray seems to be emitted from an obscure part of the plane (even x-ray mode doesn’t help), I want the ray to be emitted under the entire object. That way there is a different behavior when the player is contacting the plane (surface) and when the player is under it. Also the physics option “ghost” detects the collision sensor.
Also @BluePrintRandom have a look at solarlune’s wave script and you’ll see why I don’t want 2 objects below eachother.
i thought these were great options. Theyre telling you that you could use instead of this ray function, to make it easier on you. it might not be possible, or if it is, its really hard? or at least advanced. You asked for help, you didnt specify that you needed it to realize what you really wanted. Which in all logic means that you knew the real answer beforehand, but you wanted to share your frustration with us…
That is your most basic function. Its in your blood…cant get rid of it
@ Evil Moon MOose
I did specifically say that I plan to use Solarlune’s wave script, while these proposals are good if I were only to use a single plane, they are not efficient when it comes to using a script for the waves (I have enough lag problems as it is).
I also specifically stated that I wanted a sort of volume to be cast beneath the mesh like a ray. And you already know of the problems with the ray sensor. I do know what I want (obviously) but I DON’T know the answer, which is why I am asking how to do it.
I just wanted to know how to properly trigger these 3 states so that I could make a swimming mechanic, making a swimming mechanic with only 2 states is easy, it’s having a third state that makes the difference.
I would do this in python. Water surfaces are flat, so how much in the water the character are can easily be calculated from world z position. Then it is just to apply an upwards force and damping when under the surface and let that smoothly decrease until completely over the surface. The script can also trigger the camera to go under water when the character is under water - and change how movement controls work.
Dolphin jumping comes for free - if You under the water and swim fast upwards - when you cross the surface the up force disappears and so do the swim force - so it jump as far the speed take it and then fall to the surface again!
Such python code could fairly easy take stuff like current in to account to - possibly even waves.
@Monster, that is actually very helpful, knowing that it’s possible is a good thing to know and the zones proposal is not a bad idea.
I think with the rotating issue it may have to do with the buoyancy empties, if you could make the bottom 4 “heavier” than the top 4 I think it would stop the rotating. Ofcourse I know nothing about python so i’m probably just talking nonsense.
I guess one really needs to know Python for these things, oh well, for now I think i’ll try using the zones system which theoretically should work with logic bricks. If all else fails i’ll use a 2 state system.