Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重写物理系统 #60

Open
3 tasks
Tinellie opened this issue Oct 5, 2022 · 2 comments
Open
3 tasks

重写物理系统 #60

Tinellie opened this issue Oct 5, 2022 · 2 comments

Comments

@Tinellie
Copy link
Member

Tinellie commented Oct 5, 2022

  • 在统一的物理系统中,管理对象的碰撞体
  • 利用四叉树减少碰撞次数
  • 将对实体施加重力的行为移出实体
@Tinellie
Copy link
Member Author

Tinellie commented Oct 6, 2022

实现思路

大部分物理程序由一个类统一管理

原来的实体Update程序如下

  1. ControlUpdate(..) AI判断移动 / 玩家操作移动,更改移动状态
  2. MovementUpdate(..) 根据状态,修改玩家速度值,施加重力等,移动并判断碰撞推挤
  3. 根据 DrawMovementLine,决定是否绘制移动轨迹
  4. CombatUpdate(..) 根据当前位置,判断碰撞,对敌对目标造成伤害等
  5. DrawUpdate(..) 修改贴图相关属性

`MovementUpdate(..) 的流程如下

  1. 检测跳跃,增加 Y 速度 | Jump(JumpStatus)
  2. 检测移动,增加 X 速度 | Walk(GameTime, WalkStatus)
  3. 施加阻力,削减 X 速度 | ApplyFriction(GameTime, WalkFriction)
  4. 施加重力,减少 Y 速度 | ApplyGravity(GameTime, Gravity)
  5. 移动对象,检测碰撞推挤,返回 | OnGround MoveHitAndGroundCheck
    1. 分解处理 Y 和 X 方向的运动 | 调用两次 SpdDecompoMove(GameTime, Vel)
      1. 移动
      2. 检测碰撞 | GetHitRigidObjects(MGameMain, Hitbox)
      3. 如果不存在碰撞,return false
      4. 尝试用特定方法处理碰撞 | HitDealingAction(Vel, Hitboxes)
      5. 二分移动到合适位置 | HitMove(..)HitDichotomyMove(..)
      6. return (是否碰撞, 发生碰撞的碰撞体)
    2. 如果发生碰撞
      1. 调用 [发生碰撞的碰撞体] 的相关方法
      2. 如果向下移动碰撞,设 OnGround = true
      3. 速度归零
  6. 根据 OnGround 设置跳跃次数等 | OnGroundAction(OnGround, WasOnGround

@Tinellie
Copy link
Member Author

Tinellie commented Oct 7, 2022

实现思路

  1. 分别调用 ControlUpdate(..) 对象更改移动状态
  2. 应用立场之类的效果
  3. 由一个独立的 Manager 执行对象的移动,碰撞判定
    1. 分别移动对象
    2. 更新四叉树
    3. 如果发生碰撞,
      1. 推挤移动到合适的位置
      2. 调用有关碰撞体的事件
      3. 如果是弹幕,对有关对象造成伤害
      4. 对有关对象施加力
      5. 如果向下碰撞,设定OnGround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant