Retour Haptic Kit photon VR Shooting Range

Section dédiée à la VR avec Unity
chachinoi33
Messages : 12
Inscription : 27 Juil 2016 08:28

Retour Haptic Kit photon VR Shooting Range

Message par chachinoi33 » 20 Juin 2018 09:18

Bonjour,
Je travail depuis un petit moment sur le kit VR Shooting Range de photon engine qui est très bien, mais je m'attaque aux
finition de mon jeux. Je rencontre un problème pour integrer le retour haptic sur le gun!
Pouvez vous m'aider?
MERCI :amen:

https://assetstore.unity.com/packages/t ... oton-85121

Avatar de l’utilisateur
E3DStef
Administrateur
Administrateur
Messages : 1646
Inscription : 14 Juil 2013 18:30
Localisation : https://www.carte-des-membres.com/fr/Unity3D-France/

Re: Retour Haptic Kit photon VR Shooting Range

Message par E3DStef » 27 Juin 2018 09:44

Salut

Décris ce que tu entends par retour haptic stp ?
Le Savoir n'est Précieux que s'il est Partagé

Si besoin urgent de me contacter, faites moi un mail sur : franceunity3d@gmail.com

chachinoi33
Messages : 12
Inscription : 27 Juil 2016 08:28

Re: Retour Haptic Kit photon VR Shooting Range

Message par chachinoi33 » 30 Juin 2018 18:01

Bonjour,
Voilà dans ce kit il n'y a pas les vibrations dans le contrôleur quand le coup de feu est tiré, cette fonction steam vr permet de régler la puissance et la vibration. Quelqu'un a répondu a ma question sur le site officiel mais vu que je ne maîtrise pas le csharp impossible de le faire fonctionner.

Code : Tout sélectionner

// Haptic Functions

		protected Dictionary<SteamVR_Controller.Device,Coroutine> activeHapticCoroutines = new Dictionary<SteamVR_Controller.Device, Coroutine>();

		public void StartHapticVibration(SteamVR_Controller.Device device, float length, float strength) {

			if(activeHapticCoroutines.ContainsKey(device)) {
				Debug.Log("This device is already vibrating");
				return;
			}

			Coroutine coroutine = StartCoroutine(StartHapticVibrationCoroutine(device,length,strength));
			activeHapticCoroutines.Add(device,coroutine);

		}

		public void StopHapticVibration(SteamVR_Controller.Device device) {
			
			if(!activeHapticCoroutines.ContainsKey(device)) {
				Debug.Log("Could not find this device");
				return;
			}
			StopCoroutine(activeHapticCoroutines[device]);
			activeHapticCoroutines.Remove(device);
		}

		protected IEnumerator StartHapticVibrationCoroutine(SteamVR_Controller.Device device, float length, float strength) {

			for(float i = 0; i < length; i += Time.deltaTime) {
				device.TriggerHapticPulse((ushort)Mathf.Lerp(0, 3999, strength));
				yield return null;
			}

			activeHapticCoroutines.Remove(device);
		}
Voici le script ou doit etre inseré le code, apparemment je dois intégrer ce code après _gunFire.SetActive(true);

Code : Tout sélectionner

using UnityEngine;
using System.Collections;

namespace ExitGames.SportShooting
{
    public class Shooter : MonoBehaviour
    {
        [SerializeField]
        LineRenderer _bulletTrace;

        [SerializeField]
        Transform _tip;

        [SerializeField]
        GameObject _gunFire;

        [SerializeField]
        LayerMask _hitLayer;

        [SerializeField]
        float _maxBulletDistance;

        [SerializeField]
        NetItemsSynchronizer _synchronizer;


        RaycastHit _hitInfo;

        [SerializeField]
        protected PhotonView _photonView;

        private AudioSource _shotSound;

        public void Awake()
        {
            _shotSound = GetComponent<AudioSource>();
        }

		protected void ShootAttempt()
        {
            _gunFire.SetActive(false);
            _synchronizer.ForceUpdate();
            _bulletTrace.enabled = true;
            
            //Check if we've hit the target
            if (Physics.Raycast(_tip.position, _tip.forward, out _hitInfo, _maxBulletDistance, _hitLayer))
            {
                _bulletTrace.SetPosition(0, _tip.position);
                _bulletTrace.SetPosition(1, _hitInfo.point);

                var hittedObject = _hitInfo.collider.GetComponent<Distructable>();
                if (hittedObject != null)
                {
                    hittedObject.MarkToDestroy();
                }

                var b = _hitInfo.collider.GetComponent<NonUiButton>();
                if (b != null)
                {
                    if (b.CompareTag("EndMatchButton"))
                    {
                        b.EndMatch();
                    }
                    else if (b.CompareTag("LogoutButton"))
                    {
                        b.LeaveMatch();
                    }

                    _bulletTrace.enabled = false;
                    return;
                }
            }
            else
            {
                _bulletTrace.SetPosition(0, _tip.position);
                _bulletTrace.SetPosition(1, _tip.position + _tip.forward * _maxBulletDistance);
            }
	
            _gunFire.SetActive(true);
            
           ////////// CODE A PLACER ICI//////////
            
            _photonView.RPC("PlayShotSound", PhotonTargets.All);
            _synchronizer.ForceUpdate();
            StartCoroutine(DisableBulletTrace());

        }


        // Disable bullet trace with short timeout to create visual effect
        IEnumerator DisableBulletTrace()
        {
            yield return null;

            _bulletTrace.enabled = false;
        }

        [PunRPC]
        public void PlayShotSound()
        {
            _shotSound.PlayOneShot(_shotSound.clip);
        }
    }
}
Merci pour votre aide!!!!!!

Avatar de l’utilisateur
Max
Messages : 8764
Inscription : 30 Juil 2011 13:57
Contact :

Re: Retour Haptic Kit photon VR Shooting Range

Message par Max » 30 Juin 2018 19:04

Bonjour,

Arf, on est dans un cas de scrapscripting :mrgreen:
Tu ne peux pas coller des bouts de codes comme cela. C'est déroutant quand on débute, mais les choses ne sont pas si simples.
chachinoi33 a écrit :
30 Juin 2018 18:01
Quelqu'un a répondu a ma question sur le site officiel
il aurais été intéressant d'avoir le lien de l'échange.
Les méthodes que tu listes semblent issus de la classe HapticFeedbackController.cs, destiné visiblement à être employé comme component.
Donc à voir de ce coté là. (après niveau mise en oeuvre VR, ce n'est pas mon domaine, sorry)
Image
Pas d'aide par MP, le forum est là pour ça.
En cas de doute sur les bonnes pratiques à adopter sur le forum, consulter la Charte et sa FAQ

chachinoi33
Messages : 12
Inscription : 27 Juil 2016 08:28

Re: Retour Haptic Kit photon VR Shooting Range

Message par chachinoi33 » 30 Juin 2018 21:03

Merci de ta réponse, effectivement le copié collé sur des scripts déjà fait a leurs sauces c'est jamais terrible, mais il est vrai que j'ai gagné beaucoup de temps avec ce kit qui est super pour du multi en VR.
J'ai essayé en changeant les fonctions, paramètres, variables...mais rien n'y fait, je pense qui doit y avoir des liens sur d'autres scripts.
Quand j utilise vrtk ou steam vr sur d'autres projet je n'ai pas de soucis pour ce genre de fonction.
Voilà ce que le modérateur me répond par mail:

please take a look at this post by user MoBenZ. He describes how to start and stop Coroutines for using TriggerHapticPulse, which I guess is basically what you have to do in the VR Shooting Range demo as well. In this certain demo, there is a script called Shooter.cs, which can be found in \Assets\VR-Shooting-Range\Scripts\Entities\Player\Shooter.cs. This script contains a function called ShootAttempt. Inside this function you would have to add the code for using TriggerHapticPulse. You can add the code for using TriggerHapticPulse between lines 78 and 79.

Voici le liens de ce script que l'on peut trouver sur un fil de discution steam:

https://steamcommunity.com/app/358720/d ... 4521668855

Répondre

Revenir vers « Unity et la VR »