Beispiel #1
0
    float ComputeDuration(float speed)
    {
        float distance = Vector2.Distance(WorldConversion.ToVector2(transform.position),
                                          WorldConversion.ToVector2(_target.position));

        return(distance / speed);
    }
Beispiel #2
0
    bool IsZoneInRange()
    {
        float maxDist = _zone.radius + (_collider.radius * extendCoef);
        float dist    = Vector2.Distance(WorldConversion.ToVector2(transform.position),
                                         WorldConversion.ToVector2(_zone.transform.position));

        return(maxDist > dist);
    }
Beispiel #3
0
        public override bool Decide(Steering steering)
        {
            Vector2 playerPos2D    = WorldConversion.ToVector2(PlayerShip.instance.transform.position);
            Vector2 characterPos2D = WorldConversion.ToVector2(steering.controllerTransform.position);

            float distance = Vector2.Distance(playerPos2D, characterPos2D);

            return(_maxDistance < distance);
        }
Beispiel #4
0
    Vector3 ComputeControlPoint(EvaluationCurve xyCurve,
                                EvaluationCurve yCurve,
                                float time,
                                Vector3 from,
                                Vector3 to)
    {
        Vector2 from2D = WorldConversion.ToVector2(from);
        Vector2 to2D   = WorldConversion.ToVector2(to);

        float   distance01 = xyCurve.Evaluate(time);
        Vector2 pos2D      = (to2D - from2D) * distance01 + from2D;

        float y01 = yCurve.Evaluate(time);
        float y   = (to.y - from.y) * y01 + from.y;

        return(new Vector3(pos2D.x, y, pos2D.y));
    }
Beispiel #5
0
    void UpdateMovement(float dt)
    {
        _direction  = transform.forward * _speed;
        _direction += WorldConversion.ToVector3(_body.velocity);

        if (_direction.magnitude > _maxSpeed)
        {
            _direction.Normalize();
            _direction *= _maxSpeed;
        }

        Vector3 move = _direction * dt;

        Vector2 move2D = WorldConversion.ToVector2(move);
        float   angle  = -_angular * dt * _slideStrength * (_speed / _maxSpeed);

        move2D = MathHelper.RotateVector(move2D, angle * Mathf.Deg2Rad);
        move   = WorldConversion.ToVector3(move2D);

        _rb.velocity = move / dt;
    }