0%

How to make a 2D Game

2D Movement in Unity

<关于2D碰撞的一些优化设置>

Rigidbody2D-Collision Detection

  • Discrete

GameObjects with Rigidbody 2Ds and Collider 2Ds can overlap or pass through each other during a physics update

  • Continuous

GameObjects with Rigidbody 2Ds and Collider 2Ds do not pass through each other during an update

Physics Material 2D

  • Friction
  • Bounciness
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// CharacterController2D.cs

FixedUpdate()
{
判断角色是否落地:
在角色脚下新建一个EmptyObject, 通过Physics2D.OverlapCircleAll方法检测有什么跟角色的脚底发生了碰撞。
如果发生碰撞的不是gameObject, 那么认定角色在地面上。
}

Move()
{
如果角色在蹲着,判断是否可以站起来:

可以控制player的条件是:player在地面上或者允许player在空中移动
如果player在蹲着,那么降低移动速度

}

Flip()
{
通过让palyer的localscale的X取负数来实现左右朝向的反转
}