Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

objeto no rota adecuadamente. unity2D

Iniciado por Ness, Abril 29, 2016, 07:09:23 AM

Tema anterior - Siguiente tema
 presento el problema cuando le doy  rotar a un objeto que esta dentro de otro pero el objeto padre, lo giro el  hijo toma tambien la rotacion del padre,  el problema del hijo es que también necesito que tenga una rotacion propia y esta  se invierte cuando el objeto padre invierte su rotacion , generandome problemas.¿alguna solución al problema?


public class rotacionBrazoEnemigo : MonoBehaviour {

    private Transform player;

    private bool facingRight;


    // Use this for initialization
    void Start () {

}

// Update is called once per frame
void Update () {
        if (player == null)
        {
            player = GameObject.Find("player").GetComponent<Transform>();
        }

        transform.rotation = Quaternion.LookRotation( Vector3.forward, player.position - transform.position);

       if (player.position.x - transform.position.x > 0.1f && facingRight == false)
        {
            Flip();
        }
        else if (player.position.x - transform.position.x < -0.1f && facingRight == true)
        {
            Flip();
        }

    }

    void Flip()
    {
        // Switch the way the player is labelled as facing
        facingRight = !facingRight;

        // Multiply the player's x local scale by -1
        Vector3 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;
    }
}
[/quote] 

La gracia de las jerarquías es que se trasladen a los niveles inferiores. Por otro lado con la diferencia entre el tratamiento local al transform (una localrotation, localposition) y el tratamiento global podrías conseguirlo sin problemas.

Etiquetas: