条件:已知子弹位置,子弹速度大小m_nSpd、方向m_nAngle,目标的位置,每次转角角度FOLLOW_ANGLE
实现目标:要求子弹跟踪目标,且角度能够平滑地过度到正对目标
实现:
1、算出子弹与目标所成的角度nAngle
2、(ANGLE_CIRCLE=360)
if(m_nAngle != nAngle){ if(nAngle > m_nAngle){ if(nAngle < m_nAngle + 180){ m_nAngle += FOLLOW_ANGLE; if(m_nAngle-FOLLOW_ANGLE <= nAngle && m_nAngle >= nAngle) m_nAngle = nAngle; } else/* if (nAngle >= m_nAngle + 180)*/{ m_nAngle -= FOLLOW_ANGLE; if(m_nAngle <= 0 && -m_nAngle >= ANGLE_CIRCLE-nAngle) m_nAngle = nAngle; } } else{ if(m_nAngle < nAngle + 180){ m_nAngle -= FOLLOW_ANGLE; if(m_nAngle <= nAngle && m_nAngle+FOLLOW_ANGLE>=nAngle) m_nAngle = nAngle; } else{ m_nAngle += FOLLOW_ANGLE; if(m_nAngle >= ANGLE_CIRCLE && m_nAngle - ANGLE_CIRCLE >= nAngle){ m_nAngle = nAngle; } } } }