Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Magnus Effect for tennis ball physics simulation

Discussion in 'Physics' started by Taka33Taka33, Aug 7, 2022.

  1. Taka33Taka33

    Taka33Taka33

    Joined:
    May 15, 2022
    Posts:
    16
    I saw this post: https://forum.unity.com/threads/tennis-ball-simulation.399725/

    But I can't find the Youtube video referenced: youtube]ROYdWCs4ANs

    Can anyone help me track down information on how to implement this?

    Basically, top spin, side spin, under spin and various combinations of those should have different ball physics.
     
  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,692
    If I read the wikipedia page on Magnus effect correctly, you can implement it as a force whose direction is orthogonal to the linear velocity and angular velocity vectors (use a cross product of these to get the direction) and whose magnitude is 4/3 * pi * air density * (ball radius)^3. You can consider air density as a spatially constant parameter, that allows you to control the intensity of the effect.

    If you know your way around C#, this should be trivial to implement.
     
    wangsitan likes this.
  3. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,692
    Went ahead and implemented it for you. Just slap this component onto a rigidbody ball, adjust the radius and air density, and you're done.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. [RequireComponent(typeof(Rigidbody))]
    5. public class MagnusEffect : MonoBehaviour
    6. {
    7.     public float radius = 0.5f;
    8.     public float airDensity = 0.1f;
    9.  
    10.     private Rigidbody rb;
    11.  
    12.     void Awake()
    13.     {
    14.         rb = GetComponent<Rigidbody>();
    15.     }
    16.  
    17.     void FixedUpdate()
    18.     {
    19.         var direction = Vector3.Cross(rb.angularVelocity, rb.velocity);
    20.         var magnitude = 4 / 3f * Mathf.PI * airDensity * Mathf.Pow(radius, 3);
    21.         rb.AddForce(magnitude * direction);
    22.     }
    23. }
    24.  
     
  4. Taka33Taka33

    Taka33Taka33

    Joined:
    May 15, 2022
    Posts:
    16
  5. Entretoize

    Entretoize

    Joined:
    Feb 27, 2015
    Posts:
    44
    Quelle est l'unité de la densité de l'air dans ta formule ? Car la densité de l'air sec à température "normale" est autour de 1,2 kg/m³, tu mets 0.1...
     
  6. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,692
    Unity uses real-world units (meters for distances and kg for masses). So air density is expressed in kg/m3, you can use 1.2 if you wish to use real-world values.

    In a game you can treat air density as a parameter that drives the intensity of the Magnus effect, that's why I used 0.1 as the default, it's just an arbitrary value that you can change in the component inspector.