Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-5-sonnet-20241022· AnthropicHugging Face LMArena Human Preference 140K

How do we make water in a game engine? Making a plane and adding a shader is easy, but…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash’s answer.
  1. User

    How do we make water in a game engine? Making a plane and adding a shader is easy, but when you jump in, you go right through.

  2. Claude Assistant

    Let me help you with implementing water physics in a game engine. Here's a step-by-step approach:

    1. Basic Water Surface
    • Start with your plane and shader for visual effect
    • Add a collider component to the water plane (usually a Box Collider)
    • Make it a trigger collider rather than a solid one
    1. Water Physics Script
    public class WaterPhysics : MonoBehaviour
    {
        public float buoyancyForce = 2f;
        public float dragForce = 1f;
    
        private void OnTriggerStay(Collider other)
        {
            if (other.CompareTag("Player"))
            {
                Rigidbody rb = other.GetComponent<Rigidbody>();
                if (rb != null)
                {
                    // Calculate how deep the object is
                    float submergedDepth = transform.position.y + transform.localScale.y/2 - other.transform.position.y;
                    
                    // Apply buoyancy force
                    Vector3 buoyancy = Vector3.up * buoyancyForce * submergedDepth;
                    rb.AddForce(buoyancy);
                    
                    // Apply drag
                    rb.velocity *= (1f - dragForce * Time.deltaTime);
                }
            }
        }
    }
    
    1. Key Components to Add
    • Add drag to slow movement in water
    • Implement buoyancy force based on how deep the object is
    • Consider adding splash effects when entering water
    • Add water resistance to jumping/movement while in water
    1. Additional Enhancements
    • Add waves using sine waves in the shader and physics
    • Implement water ripples when objects enter
    • Add swimming mechanics for the player
    • Consider water displacement for larger objects

    Would you like me to elaborate on any of these aspects or provide more specific code examples for a particular game engine?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.