En este momento estás viendo ¿Cómo establecer la posición de un objeto de juego en la posición inicial después de que el agarre haya terminado usando la mano en SteamVR usando Unity?

 – Unity

¿Cómo establecer la posición de un objeto de juego en la posición inicial después de que el agarre haya terminado usando la mano en SteamVR usando Unity? – Unity

¿Cómo establecer la posición de un objeto de juego en la posición inicial después de que el agarre haya terminado usando la mano en SteamVR usando Unity?

– UnityAssets3Free

hola , por aqui josel luis y en esta ocasion os traigo
esta unity pregunta

Muy nuevo en realidad virtual. Tomé un objeto de juego desde una posición temprana agarrándolo. Cuando tomo un casco y toco el cuerpo de mi colisionador, oculta el casco. cuando me pongo el casco incorrecto, el primer casco debería volver a su posición inicial y debería verse en la escena. Asimismo, hay muchos GameObjects en la escena.

 private void OnTriggerEnter(Collider other)
        

    if (other.gameObject.tag == "Helmet")
    

       
        HideGameObject();
      
       
    

    if (other.gameObject.tag == "Glasses")
    

        HideGameObject();           
       
    
    if (other.gameObject.tag == "EarMuff")
    
        HideGameObject();
       
    
   
    

    if (other.gameObject.tag == "IncorrectHelmet")
    

      
        HideGameObject();
       

    

    if (other.gameObject.tag == "IncorrectGlasses")
    
        HideGameObject();
        

    


    if (other.gameObject.tag == "IncorrectEarMuff")
    
        HideGameObject();
        sendPickValues.Invoke(2, 0);

    
    


 

//Otro script para establecer la posición de GameObjects

public class BackToPosition : MonoBehaviour


private Vector3 initialPosition;
private Quaternion initialRotation;

GameObject prevObject;
GameObject currObject;



// Start is called before the first frame update
void Start()

    initialPosition = transform.position;
    initialRotation = transform.rotation;


// Update is called once per frame
void Update()

    


public void BackToInitialPosition()

    Debug.Log("Entered");
    transform.position = initialPosition;
    transform.rotation = initialRotation;
                               
    


No estoy tratando de colocar el objeto agarrado anterior en la posición inicial. Puedo seleccionar primero el casco equivocado y elegir muchos otros objetos del juego que coincidan y luego cambiar al casco correcto. En este punto, el primer casco debe ir a la posición inicial.

2 respuestas 2

Esta es una secuencia de comandos que uso en SteamVR para agarrar y soltar la manija del timón de un barco, pero también debería ser útil para usted:

[RequireComponent(typeof(Interactable))]
public class HandAttacher : MonoBehaviour

    public UnityEvent OnGrab;
    public UnityEvent OnRelease;
    public UnityEvent OnHandEnter;
    public UnityEvent OnHandLeave;

    private Interactable interactable;

    void Awake()
    
        interactable = GetComponent<Interactable>();
    

    /// this magic method is called by hand while hovering
    protected virtual void HandHoverUpdate(Hand hand)
    
        GrabTypes startingGrabType = hand.GetGrabStarting();

        if (interactable.attachedToHand == null && startingGrabType != GrabTypes.None)
        
            hand.AttachObject(gameObject, startingGrabType, Hand.AttachmentFlags.DetachFromOtherHand 
    

    protected virtual void OnHandHoverBegin(Hand hand)
    
        OnHandEnter?.Invoke();
    

    protected virtual void OnHandHoverEnd(Hand hand)
    
        OnHandLeave?.Invoke();
    

    protected virtual void HandAttachedUpdate(Hand hand)
    
        if (hand.IsGrabEnding(gameObject))
        
            hand.DetachObject(gameObject);
            OnRelease?.Invoke();
        
    

Básicamente, crea eventos de Unity a los que puede agregar oyentes en la ventana Inspector del Editor o en el código.

Entonces, en su caso de uso, agregaría un oyente a OnReleasey restablecer la posición y la rotación del GameObject a lo que era antes.

Intenté usar BackToPosition o algo similar en Update comparando la posición original con la actual para restablecer la posición del objeto, y el objeto sigue restableciéndose en un bucle en lugar de restablecerse a su posición original y detenerse.

nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias

por hoy,hasta la proxima

Deja una respuesta