# BallBounce

## Overview

`BallBounce` is a data type that holds the state of a ball when it collides (bounces) with a surface. It provides information necessary for analyzing bounce events, such as the direction/speed/spin and angular velocity just before collision, the time of collision, the changes in direction/speed/spin after collision, and the collision point/normal. It is used for displaying replays, tuning physics parameters, and debugging collision responses.

## Constructors

It is not created directly in scripts. Typically, it is returned as a bounce event or passed as a callback argument during the simulator/engine's collision processing.

## Properties

### CFrame

`CFrame`

The ball's posture based on the collision point (based on `HitPosition + HitRotation`). Includes both position and rotation.

#### Code Samples

```lua
local bounce = bounce -- BallBounce received from the simulator
print("Bounce CFrame:", bounce.CFrame)
```

### Direction

`Vector3`

The unit vector of the movement direction just before the collision.

#### Code Samples

```lua
local bounce = bounce
print("Incoming dir:", bounce.Direction)
```

### Speed

`number`

The speed magnitude just before the collision (cm/s).

#### Code Samples

```lua
local bounce = bounce
print("Incoming speed (cm/s):", bounce.Speed)
```

### Spin

`number`

The spin just before the collision (angular velocity magnitude, rad/s).

#### Code Samples

```lua
local bounce = bounce
print("Incoming spin (rad/s):", bounce.Spin)
```

### AngularVelocity

`Vector3`

The angular velocity vector just before the collision (rad/s). The direction is the axis of rotation, and the magnitude is the angular speed.

#### Code Samples

```lua
local bounce = bounce
print("Incoming ang vel:", bounce.AngularVelocity)
```

### BouncedTime

`number`

The time when the bounce occurred (seconds). This is the time value on the simulation timeline.

#### Code Samples

```lua
local bounce = bounce
print("Bounce time (s):", bounce.BouncedTime)
```

### BouncedDirection

`Vector3`

The unit vector of the movement direction after the collision.

#### Code Samples

```lua
local bounce = bounce
print("Outgoing dir:", bounce.BouncedDirection)
```

### BouncedSpeed

`number`

The speed magnitude after the collision (cm/s).

#### Code Samples

```lua
local bounce = bounce
print("Outgoing speed (cm/s):", bounce.BouncedSpeed)
```

### BouncedSpin

`number`

The spin after the collision (angular velocity magnitude, rad/s).

#### Code Samples

```lua
local bounce = bounce
print("Outgoing spin (rad/s):", bounce.BouncedSpin)
```

### BouncedAngularVelocity

`Vector3`

The angular velocity vector after the collision (rad/s).

#### Code Samples

```lua
local bounce = bounce
print("Outgoing ang vel:", bounce.BouncedAngularVelocity)
```

### bIsSliding

`boolean`

Whether the ball is sliding on the contact surface after the collision.

#### Code Samples

```lua
local bounce = bounce
print("Is sliding:", bounce.bIsSliding)
```

### StartPos

`Vector3`

The start position of the bounce simulation segment.

#### Code Samples

```lua
local bounce = bounce
print("Start pos:", bounce.StartPos)
```

### BouncedPosition

`Vector3`

The position of the collision point.

#### Code Samples

```lua
local bounce = bounce
print("Hit position:", bounce.BouncedPosition)
```

### BouncedRotation

`CFrame`

The rotation (posture) of the collision point. Stored as `FQuat` in code but denoted as `CFrame` in documentation (rotation component).

#### Code Samples

```lua
local bounce = bounce
print("Hit rotation:", bounce.BouncedRotation)
```

### ImpactPoint

`Vector3`

The world coordinates of the collision contact point.

#### Code Samples

```lua
local bounce = bounce
print("Impact point:", bounce.ImpactPoint)
```

### ImpactNormal

`Vector3`

The normal vector of the collision surface (perpendicular to the surface).

#### Code Samples

```lua
local bounce = bounce
print("Impact normal:", bounce.ImpactNormal)
```

## Methods

There are currently no methods exposed externally.

## See also

{% content-ref url="../classes/simulationball" %}
[simulationball](https://docs.overdare.com/development/api-reference/classes/simulationball)
{% endcontent-ref %}
