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
->Sprite
and name itBall
.
-
Create a circle sprite by selecting
Create
->Sprites
->Circle
in theProject
windows. -
Assign the circle sprite to the
Ball
2D GameObject. -
Reset the
Transform
component of theBall
GameObject to make sure it is positioned at(0 ,0, 0)
. -
Add a ParallelRigidbody2D componenet to the
Ball
GameObject.
- Add a ParallelCircleCollider componenet to the
Ball
GameObject.
Creating the paddles¶
-
Create a 2D Sprite GameObject by selecting
2D Object
->Sprite
and name itPaddle
. -
Create a box sprite by selecting
Create
->Sprites
->Square
in theProject
windows. -
Assign the box sprite to the
Paddle
GameObject. -
Move the
Paddle
to(-10, 0, 0)
. -
Set the
Scale
ofPaddle
to(1, 3, 1)
. -
Add a ParallelRigidbody2D componenet to the
Paddle
GameObject. -
Add a ParallelBoxCollider componenet to the
Paddle
GameObject. -
Set
Body Type
of the ParallelRigidbody2D component toKinematic
.
- Drag the
Paddle
to theProject
window to make it a prefab and make anotherPaddle
at(10, 0, 0)
.
Creating the walls¶
-
Create a 2D Sprite GameObject by selecting
2D Object
->Sprite
and name itWall
. -
Assign the box sprite to the
Wall
GameObject. -
Move the
Wall
to(0, 5, 0)
. -
Set the
Scale
ofWall
to(21, 1, 1)
. -
Add a ParallelRigidbody2D componenet to the
Wall
GameObject. -
Add a ParallelBoxCollider componenet to the
Wall
GameObject. -
Set
Body Type
of the ParallelRigidbody2D component toStatic
. -
Duplicate the
Wall
and place the duplicatedWall (1)
at(0, -5, 0)
.
Setting up the camera¶
- Set
clear Flags
of the Main Camera toSolid Color
. - Set
Background
of the Main Camera to black. - Set
Aspect ratio
of theGame
window to16:9
.
Final touch¶
You can change the color of the sprite to your liking. The scene should look like.