I saw this post: Tennis ball simulation

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.

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.

1 Like

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.

```
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class MagnusEffect : MonoBehaviour
{
public float radius = 0.5f;
public float airDensity = 0.1f;
private Rigidbody rb;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
var direction = Vector3.Cross(rb.angularVelocity, rb.velocity);
var magnitude = 4 / 3f * Mathf.PI * airDensity * Mathf.Pow(radius, 3);
rb.AddForce(magnitude * direction);
}
}
```

5 Likes

@arkano22 Thanks very much!

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…

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.