- Home /
"Swimming" Physics with Rigidbodies
I've always been stumped when it comes to this question. The best reference I can say is that I want to replicate a swimming physics setup like in Super Mario 64 (1996, Nintendo 64 title for those devs that go "uh?").
In Mario 64's implementation, there's two things I can see - one, the gravity changes to a more "slower" pull down rather than the on-land gravity, and when you press A to swim it applies some upwards momentum, as well as the direction you're traveling - so you end up going forwards on the Z axis Mario's facing (so to speak) and also a little up on the Y axis.
Unlike previous attempts where I killed gravity all together and I'm not doing that again because it caused my character's setup to do barrel rolls, I'm unsure how I would implement it.
I was wondering if anyone had any ideas on how to do underwater physics. I could use Character Controller and manually do gravity, but I perfer to use Rigidbody where possible (as it allows for more dynamic forces, etc). Do I tweak the gravity?
I do apologise for having no code, but I'm just collecting some implementation ideas before I put the pencil to the IDE.
Cheers!
Answer by FirePlantGames · Jul 07, 2015 at 12:53 AM
Well. Irrelevant note, but I'm pretty sure every dev knows what you're talking about when you mention SM64. But on topic; I think the best concept is to death the gravity and but keep friction. I don't have code to show for this, but since you didn't provide any, I am not obligated to either :P But that concept is probably your best bet, as this is essentially what SM64 water physics does.
So, i would lower the gravity "pull" (I think the default is like -9.81 in Unity3D physics) to say half that? Seems like a reasonable experiement.
Yep. But also add enough force "upwards" (On a global scale) to keep the consistent falling from pulling to fast and not like your underwater at all.
Sure you cooould do that if you want to be logical and easy about it.
I would highly recommend not changing the gravity from -9.81. Ins$$anonymous$$d, change the rigidbody's gravity scale from 1 to something like 0.25. If you change the global gravity setting, than anything that is above water will also act like it's under water.
$$anonymous$$aybe set the entire water surface as a trigger. When entering the water, set gravity to 0.25. When exiting the water, set gravity back to 1.
Answer by MCoburn · Jul 08, 2015 at 03:28 AM
Alright, so what I did was increase the drag on the character, to cause it to slow down. So the winner is memorymod with a bonus point to darkhog.
Now... time to implement this with the controller scripts...
Thanks for the help, I appreciate it.