- Home /
On Collision with water buoyancy and play Swim animation
How would i achieve some sort of buoyancy and to tell my player to animate the "Swim" Animation.. I have seen some buoyancy scripts but i haven't really seen one that looks good and im not to sure how to tell a character to play a animation once i enter water. thanks.
Answer by Devon Hall · Sep 01, 2012 at 07:38 AM
So If you have been through any modern Science class you should know a bit about Density.
Programming water at a reasonable cost of memory and CPU Usage and such is a bit of a feat.
So usually we just make either a cube in which has a fancy textured/animated plane on top to make it look nice but colliders are a little bit confusing when we get into this. Since most Colliders well, Collide and prevent objects from going through we run into a wall. Unity has actually been very good to us Devs and added the option to colliders to add a isTrigger option in which allows an object to pass through it but still detects collisions.
So using OnTriggerEnter, OnTriggerExit, and OnTriggerStay you can detect when the player is in and out etc.
But that usually isn't good enough to simply achieve the effective no glitches water effect. Making an animation play when the player enters is simple by just detecting when the player enters and using SendMessage you can tell it to play an animation safely inside the object.
But back to the glitching part. Usually before exiting the water the player might be walking on a slope up and to fix any glitches with this you can use RayCasting to the players feet to detect if the player is able to walk.
Hope I could help!
Your answer
Follow this Question
Related Questions
Get altitude of the WaterPro's wave 0 Answers
Alan Wake style 3rd person character controls, help! 1 Answer
How to "Increase score with Y axis"? 1 Answer
How do i make the game start so that the character is already running? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers