예제 #1
0
    // Update is called once per frame
    void Update()
    {
        //Gambiarra para lidar com estrutura morta
        if (target == null)
        {
            target = EnemySpawn.getBuilding().transform;
        }
        Vector3 dir = target.position - myTransform.position;

        if (dir != Vector3.zero)
        {
            float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
            _rigidbody.MoveRotation(Mathf.MoveTowardsAngle(_rigidbody.rotation, angle, rotationSpeed * Time.deltaTime));

            //myTransform.rotation = Quaternion.Slerp (myTransform.rotation,
            //Quaternion.FromToRotation(Vector3.right, dir), rotationSpeed * Time.deltaTime);
        }


        //myTransform.position += (target.position - myTransform.position).normalized * moveSpeed * Time.deltaTime;
        _rigidbody.velocity = dir.normalized * moveSpeed;
    }