> A guide on best practices to port a Physics V1 scene to V2

Source: https://doc.babylonjs.com/features/featuresDeepDive/physics/migrate

# Migrate from Physics V1

Babylon 6.0 brought a new physics architecture, which aims to provide functionality closer to what most existing physics engines provide. However, it also includes some extra classes to make this migration easier. Here, we show two ways to migrate your existing V1 scene to V2:

## Option 1: Using Aggregates

[Aggregates](https://doc.babylonjs.com/features/featuresDeepDive/physics/aggregates) work very similarly to the V1 Physics Impostors, creating all necessary objects automatically based on the parameters. So, if you have this code in V1:

```javascript
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter: 2, segments: 32 }, scene);
const impostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1, friction: 0.2, restitution: 0.3 }, scene);
```

You only need to change it to:

```javascript
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter: 2, segments: 32 }, scene);
const aggregate = new BABYLON.PhysicsAggregate(sphere, BABYLON.PhysicsShapeType.SPHERE, { mass: 1, friction: 0.2, restitution: 0.3 }, scene);
```

Note we switched the constructor from `PhysicsImpostor` to `PhysicsAggregate`, and the second parameter (the type of the physical shape) from `BABYLON.PhysicsImpostor.SphereImpostor` to `BABYLON.PhysicsShapeType.SPHERE`. [Here are the available types of shapes](https://doc.babylonjs.com/features/featuresDeepDive/physics/rigidBodies#shape).

## Option 2: No Aggregates

One of the most important new features in the new architecture is the ability to fine-tune collision shapes and reuse them, improving memory usage and customizability. So it is also possible to create bodies and shapes separately:

```javascript
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter: 2, segments: 32 }, scene);
const impostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1, friction: 0.2, restitution: 0.3 }, scene);
```

Would become:

```javascript
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter: 2, segments: 32 }, scene);
const sphereShape = new BABYLON.PhysicsShapeSphere(new BABYLON.Vector3(0, 0, 0), 1, scene);
const sphereBody = new BABYLON.PhysicsBody(sphere, BABYLON.PhysicsMotionType.DYNAMIC, false, scene);
sphereShape.material = { friction: 0.2, restitution: 0.3 };
sphereBody.shape = sphereShape;
sphereBody.setMassProperties({ mass: 1 });
```

The advantage of this approach is that, if you have another mesh you want to use with the same collider shape and material, you can reuse the shape:

```javascript
const complexModel = await BABYLON.ImportMeshAsync(...);
const body = new BABYLON.PhysicsBody(complexModel, BABYLON.PhysicsMotionType.DYNAMIC, false, scene);
body.shape = sphereShape;
body.setMassProperties({mass: complexModelMass});
```

- [Playground: Shapes test](https://playground.babylonjs.com/#Q6TJRN#7) - Use all available shapes with or without aggregates.
