-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple Swimming and Object water physics #246
base: main
Are you sure you want to change the base?
Conversation
WaterMaker3D (not essential, just a really useful scene for quickly blocking out water) made by majikayogames with CC0 licensing.
addon for doing water physics stuff. Only used for the RigidBodies, I have separate code for the player.
added ability for objects to sink or float (if they are a RigidBody3D)
swimming behaviors
My player node has some additional raycasts to help with the player being able to climb out of water. There's also a raycast to detect if your mouth is underwater, which could be used for a breath meter. (that's something I'm working on)
Thanks for creating this PR. |
updated to my current version of cogito_player.gd to try and resolve issues with the pull request. some features of Cogito may be missing and unfortunately all my comments are gone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just copy pasted my current cogito_player.gd script in. I don't have comments because I basically know what the code is doing (since i hacked it in) sorry.
ctrl+f for _handle_water_physics that's the main function for handling water movement. I call it in _physics_process sometime after some camera stuff is done processing. There's probably a better place to put the early exit for swimming behaviors.
Underneath it is the stuff for handling pushing the player out of water if they're trying to climb out.
saw some weirdness in my last update. i think github is doing some nonsense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my last update didnt copy paste properly so I fixed it I hope?
Thanks, yeah, the This is pretty cool! I don't think it's too janky, but I get what you mean that it can use some refinement. I'm going to be away for the next few days, but I think this would be a fantastic addition to COGITO. Will try to dive deeper into it when I'm back. |
breath meter functionality added
for losing oxygen when underwater.
fixed the texture to a generic COGITO one to avoid potential errors for other people looking at this.
updates to WaterMaker3D to make it work with the new junk I added. Some temporary splash effects, but I'm still kind of a novice at using AudioStream stuff so it's very jank still.
updates to WaterMaker3D to make the new features I added to the player work right. Also some splash sound stuff but it's whack.
splash effect that doesn't work and the sounds that do work.
That actually is great for me because I finished up the last of the additions you'd normally see in this kind of system. I cleaned up the player's water leaving check and made it a lot more reliable, added some splash sounds to make the water feel more watery, and cleaned up the player's water movement and the checks in general. I tried to make some swimming "footsteps" but I couldn't figure out how to do it. Seems like my limitation is the way the footstep node works, and I'm too tired of working on this system to figure out how to fix it. Thinking about making the water wet as well but I'll figure that out later when I have more of my own game developed. If you have the WaterMaker3D from a few commits ago, I'd back it up because the new one I'm using may be kind of whack. |
The footstep system uses a raycast under the player to find a surface they are standing on. It's likely the raycast isn't hitting anything when the player is swimming with your system. It's probably just better to play a swimming sound from the player controller. |
some alterations to allow for the splash effect (WHICH I FIXED) and sounds.
fixed the splash effect, i'm an idiot.
i fixed the splash effect. EDIT: Gotcha! That's kind of what it seemed like but I am very tired of working on this. I only fixed the splash out of stubbornness, lol. Hopefully this helps! |
Took a quick look again, great work on the progress of this! Latest commit throws some errors with how the breathing attribute checks the head level of the player script. One way to decouple might be to make the attribute a Node3D and use its position within the player scene to check for water submersion? That way no extra code on the player script would be needed and It's easy to customize. |
Sorry I have not worked on this in a few days, I've been busy. I'll take another look this weekend. |
All good, no rush! Appreciate your contribution. |
Utilizing the CC0 PackedScene WaterMaker3D by MajikayoGames, as well as a method he had taught me for implementing swimming into a different style of game, I managed to hack together physics for Player swimming. I extended his scene somewhat using the addon floatable_body to define the water area as a Fluid area, and then managed to trick the CogitoObject into calling RigidBody3D nodes when applicable. Then by hacking in pieces of the addon, and slowly losing sanity, I managed to get the RigidBody3Ds floating. You can pick them up, toss them around, and they either float or sink depending on how you define it.
SUPER JANK!
What's needed:
WaterMaker3D is actually not explicitly needed, I just use it for quickly blocking out water areas. All you need is an Area3D in the group "water_area" and attach the fluid_area_3d script to it. Make sure to attach the signals from the Area into the fluid_area_3d script or you will be screaming at your computer for an hour trying to figure out what you screwed up.
water_area is for the player, and the script is for the objects. You could unify it, but I didn't want to figure out how to make swimming behaviors work with the floating_bodies addon. I was just tired of trying to figure out physics calculations for floating bodies.