Search Unity

How to simulate physics of stone skipping in water (Unity 3d)

Discussion in 'Physics' started by omfg_space, Jul 9, 2020.

  1. omfg_space

    omfg_space

    Joined:
    Mar 5, 2018
    Posts:
    4

    Hello there,

    I am new to unity and I know all the basics, but I am stuck here in an issue of how can I simulate the process of skipping stones on a plane(water). Can anyone just guide me in a proper direction, so I can work in that direction!

    I know it can be achieved with or without physics but I am not sure where to start.

    Thanks in advance.
     
  2. noyogiisMYusername

    noyogiisMYusername

    Joined:
    May 18, 2020
    Posts:
    21
    Can you start with where you are stuck. Have you tried a squashed bouncy ball on a plain? Can you elaborate on what results you are looking for, a simulation based on looks or physics, do you want something that looks like a skipping stone or a physics model.
    When dealing with 3d art, an early question to ask is why am I doing this. Am I looking for an effect or am I trying to explore physics simulations. There is great art in the illusion of 3d simulation, we can build a 3d world on the computer, run around it and make the computer run a lot of numbers or we can create the illusion of a simulated 3d with minimal resources.
    A little more info on what you are looking to get out of this will likely bring in better responses. Skipping stones is fun.
     
    Last edited: Jul 13, 2020
    omfg_space likes this.
  3. omfg_space

    omfg_space

    Joined:
    Mar 5, 2018
    Posts:
    4
    Currently, I am using this below script to make the stone skip in the water, based on my prescribed figures.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class BallLauncher : MonoBehaviour
    6. {
    7.     public static BallLauncher instance;
    8.  
    9.     public Rigidbody ball;
    10.     public Transform[] target;
    11.     public int i;
    12.  
    13.     public float h = 25;
    14.     public float gravity = -18;
    15.  
    16.     private void Awake()
    17.     {
    18.         if (instance == null)
    19.         {
    20.             instance = this;
    21.         }
    22.         else
    23.         {
    24.             Destroy(gameObject);
    25.         }
    26.     }
    27.  
    28.     private void Start()
    29.     {
    30.         i = 0;
    31.         ball.useGravity = false;
    32.     }
    33.  
    34.     private void Update()
    35.     {
    36.         if(Input.GetKeyDown(KeyCode.Space))
    37.         {
    38.             Launch();
    39.         }
    40.     }
    41.  
    42.     public void Launch()
    43.     {
    44.         Physics.gravity = Vector3.up * gravity;
    45.         ball.useGravity = true;
    46.         ball.velocity = CalculateLaunchVelocity();
    47.         print(CalculateLaunchVelocity());
    48.         i++;
    49.     }
    50.  
    51.     Vector3 CalculateLaunchVelocity()
    52.     {
    53.         float displacementY = target[i].position.y - ball.position.y;
    54.         Vector3 displacementXZ = new Vector3(target[i].position.x - ball.position.x, 0, target[i].position.z - ball.position.z);
    55.  
    56.         Vector3 velocityY = Vector3.up * Mathf.Sqrt(-2 * gravity * h);
    57.         Vector3 velocityXZ = displacementXZ / (Mathf.Sqrt(-2 * h / gravity) + Mathf.Sqrt(2 * (displacementY - h) / gravity));
    58.         h = h - 2;
    59.         return velocityXZ + velocityY;
    60.        
    61.     }
    62.  
    63.  
    64. }
    65.  
    Here the targets array are the number of jumps the stone will do on the water and i have placed the target transform on water at different interval which you can see in the screenshot with yellow gizmos, so the stone will do the jump on each target location. But i am not getting that perfect effect which i want for the stone skipping which you can see in this game: https://play.google.com/store/apps/details?id=com.wildbeep.stoneskimming

    if possible you can download that game and see the result
     

    Attached Files: