Unity Spain

Post Antiguos => General (Antiguo) => Mensaje iniciado por: Ness en Abril 29, 2016, 07:09:23 AM

Título: objeto no rota adecuadamente. unity2D
Publicado por: Ness en Abril 29, 2016, 07:09:23 AM
 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] 
Título: objeto no rota adecuadamente. unity2D
Publicado por: iRobb en Abril 29, 2016, 09:08:26 AM
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.