示例#1
0
    public override void _Update(float deltaTime, ViVector3 target)
    {
        ViDebuger.AssertWarning(deltaTime > 0.0f);
        ViDebuger.AssertWarning(_speed > 0.0f);
        //
        //
        ViVector3 targetPos = Target.Value;
        float     distanceH = ViMath2D.Length(targetPos.x, targetPos.y, Translate.x, Translate.y);
        float     distanceV = targetPos.z - Translate.z;
        float     time      = distanceH / _speed;

        m_GravityAcc = -2.0f * (distanceV / (time * time) - _velocity.z / time);
        m_GravityAcc = ViMathDefine.Clamp(m_GravityAcc, -GRAVITY, 5.0f * GRAVITY);
        ViVector3 kDir = targetPos - Translate;

        kDir.z = 0.0f;
        kDir.Normalize();
        _velocity.x  = kDir.x * _speed;
        _velocity.y  = kDir.y * _speed;
        _velocity.z -= m_GravityAcc * deltaTime;
        _direction   = _velocity;
        _direction.Normalize();
    }
示例#2
0
 public static float Angle(ViVector3 from, ViVector3 to)
 {
     return(ViMathDefine.Acos(ViMathDefine.Clamp(Dot(from.normalized, to.normalized), -1f, 1f)));
 }