Physics 2D¶
FrameSync comes with a built-in physics engine to help you simulate physics in your game.
In this tutorial, you are going to use the build-in 2D physics to simulate the ball's movment.
For your first step, you will create a 2D Physics Controller.
Right-Click in the Hierarchy window and select Parallel->2D->Physics Controller.
Rigidbodies¶
Next, you will create the following Rigidbodies.
| Name | Body Type | Description |
|---|---|---|
| Ball | Dynamic | Controlled by physics |
| Paddles | Kinematic | Controlled by players |
| Walls | Staic | Do not move |
Creating the ball¶
- Create a 2D Sprite GameObject by selecting
2D Object->Spriteand name itBall.
-
Create a circle sprite by selecting
Create->Sprites->Circlein theProjectwindows. -
Assign the circle sprite to the
Ball2D GameObject. -
Reset the
Transformcomponent of theBallGameObject to make sure it is positioned at(0 ,0, 0). -
Add a ParallelRigidbody2D componenet to the
BallGameObject.
- Add a ParallelCircleCollider componenet to the
BallGameObject.
Creating the paddles¶
-
Create a 2D Sprite GameObject by selecting
2D Object->Spriteand name itPaddle. -
Create a box sprite by selecting
Create->Sprites->Squarein theProjectwindows. -
Assign the box sprite to the
PaddleGameObject. -
Move the
Paddleto(-10, 0, 0). -
Set the
ScaleofPaddleto(1, 3, 1). -
Add a ParallelRigidbody2D componenet to the
PaddleGameObject. -
Add a ParallelBoxCollider componenet to the
PaddleGameObject. -
Set
Body Typeof the ParallelRigidbody2D component toKinematic.
- Drag the
Paddleto theProjectwindow to make it a prefab and make anotherPaddleat(10, 0, 0).
Creating the walls¶
-
Create a 2D Sprite GameObject by selecting
2D Object->Spriteand name itWall. -
Assign the box sprite to the
WallGameObject. -
Move the
Wallto(0, 5, 0). -
Set the
ScaleofWallto(21, 1, 1). -
Add a ParallelRigidbody2D componenet to the
WallGameObject. -
Add a ParallelBoxCollider componenet to the
WallGameObject. -
Set
Body Typeof the ParallelRigidbody2D component toStatic. -
Duplicate the
Walland place the duplicatedWall (1)at(0, -5, 0).
Setting up the camera¶
- Set
clear Flagsof the Main Camera toSolid Color. - Set
Backgroundof the Main Camera to black. - Set
Aspect ratioof theGamewindow to16:9.
Final touch¶
You can change the color of the sprite to your liking. The scene should look like.