[DB]Gestion Manette

Pour les scripts écrits en C#
Règles du forum
Merci de respecter la NOMENCLATURE suivante pour vos TITRES de messages :

Commencez par le niveau de vos scripts
DB = Débutant
MY = Moyen
CF = Confirmé

Puis le domaine d'application
-RS = Réseau
-AL = Algorithmie

Exemple :

[DB-RS] Mouvement perso multijoueur
Avatar de l’utilisateur
shei48
Messages : 6
Inscription : 19 Mai 2017 22:13

[DB]Gestion Manette

Message par shei48 » 17 Avr 2019 13:17

Bonjour,

Actuellement je travaille sur un jeu de drone fpv,
J'ai trouver un script pour faire voler le drone qui et vraiment énorme qui et sur un rigidbody.

Mon soucis j'aimerais brancher une radiocommande de drone pour pouvoir le piloter

je branche ma radiocommande qui et bien détecté par unity donc je configure par l'input manager les axe vertical et horizontale qui me serve a avancer et a tourner sur 1 des deux joystick de ma manette .

Et la vient le tour de mon deuxième joystick qui normalement doit me faire pivoter ainsi que monter descendre .ce joystick correspond sur l'input manager au 3rd axis .



et la impossible de faire pivoter le drone de droite a gauche ou monter descendre alors les touches assigner pour c'est fonction la son I,K pour monter descendre et J,L pour pivoter de droite et gauche ensuite j'ai Z,S pour inclinai le drone pour avancer d'avant en arrière et Q,D pour incliner le drone de droite a gauche

Code : Tout sélectionner

 void Awake()
    {
        droneFirst = GetComponent<Rigidbody>();
        droneSound = gameObject.transform.Find("DroneSound").GetComponent<AudioSource>();
    }

    
    void FixedUpdate()
    {
        MonterDescendre();
        AvancerReculer();
        Rotation();
        clampingSpeedValues();
        deviant();
        DroneSound();
        

        droneFirst.AddRelativeForce(Vector3.up * upForce);
        droneFirst.rotation = Quaternion.Euler(
            new Vector3(inclinaisonPourAvancer, currentYRotation, tiltamountsideways)
            );
           
    }

    public float upForce;
    void MonterDescendre()
    {
        if((Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f || Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f))
        {
        if (Input.GetKey(KeyCode.I) || Input.GetKey(KeyCode.K))
                {
                droneFirst.velocity = droneFirst.velocity;
            }
        if (!Input.GetKey(KeyCode.I) && !Input.GetKey(KeyCode.K) && !Input.GetKey(KeyCode.J) && !Input.GetKey(KeyCode.L))

                {
                droneFirst.velocity = new Vector3(droneFirst.velocity.x, Mathf.Lerp(droneFirst.velocity.y, 0, Time.deltaTime * 5), droneFirst.velocity.z);
                upForce = 281;
            }
        if(!Input.GetKey(KeyCode.I) && !Input.GetKey(KeyCode.K) && Input.GetKey(KeyCode.J) || Input.GetKey(KeyCode.L))

            {
                droneFirst.velocity = new Vector3(droneFirst.velocity.x, Mathf.Lerp(droneFirst.velocity.y, 0, Time.deltaTime * 5), droneFirst.velocity.z);
                upForce = 110;

            }

            if(Input.GetKey(KeyCode.J) || Input.GetKey(KeyCode.L))
            {
                upForce = 410;
            }

            if (Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)

            {
                upForce = 135;


            }



        }

        if (Input.GetKey(KeyCode.I))
        {
            upForce = 450;
            if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f)
                {
                upForce = 300;
            }
        }

        else if (Input.GetKey(KeyCode.K))
        {
            upForce = -200;
        }

        else if (!Input.GetKey(KeyCode.I) && !Input.GetKey(KeyCode.K) && Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) < 0.2f)

        {
            upForce = 98.1f;

        }
    }

    private float Vitessedeplacement = 500.0f;
    private float inclinaisonPourAvancer = 0;
    private float velociteDinclinaisonAvancer;
    

    void AvancerReculer()

    {
        if (Input.GetAxis("Vertical") != 0)
        {
            droneFirst.AddRelativeForce(Vector3.forward * Input.GetAxis("Vertical") * Vitessedeplacement);
            inclinaisonPourAvancer = Mathf.SmoothDamp(inclinaisonPourAvancer, 20 * Input.GetAxis("Vertical"), ref velociteDinclinaisonAvancer, 0.1f);
        }

    }
    private float RechercheYRotation;
    private float currentYRotation;
    private float rotateAmoutByKeys = 2.5f;
    private float rotationYVelocity;
    void Rotation()
    {
        if(Input.GetKey(KeyCode.J))
        {
            RechercheYRotation -= rotateAmoutByKeys; 
        }

        if (Input.GetKey(KeyCode.L))
        {
            RechercheYRotation += rotateAmoutByKeys;
        }

        currentYRotation = Mathf.SmoothDamp(currentYRotation, RechercheYRotation, ref rotationYVelocity, 0.25f);
    }
    private Vector3 velocityToSnoothDampToZero;
    void clampingSpeedValues()
    {
        if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
            {
            droneFirst.velocity = Vector3.ClampMagnitude(droneFirst.velocity, Mathf.Lerp(droneFirst.velocity.magnitude, 10.0f, Time.deltaTime * 5f));

        }

        if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) < 0.2f)
        {
            droneFirst.velocity = Vector3.ClampMagnitude(droneFirst.velocity, Mathf.Lerp(droneFirst.velocity.magnitude, 10.0f, Time.deltaTime * 5f));

        }

        if (Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
        {
            droneFirst.velocity = Vector3.ClampMagnitude(droneFirst.velocity, Mathf.Lerp(droneFirst.velocity.magnitude, 5.0f, Time.deltaTime * 5f));

        }

        if (Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) < 0.2f)
        {
            droneFirst.velocity = Vector3.SmoothDamp(droneFirst.velocity, Vector3.zero, ref velocityToSnoothDampToZero, 0.95f);
            
        }



    }
    private float sideMovementAmount = 300.0f;
    private float tiltamountsideways;
    private float titamountVelocity;
    void deviant()
    {
        if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
        {

            droneFirst.AddRelativeForce(Vector3.right * Input.GetAxis("Horizontal") * sideMovementAmount);
            tiltamountsideways = Mathf.SmoothDamp(tiltamountsideways, -1 * 20 * Input.GetAxis("Horizontal"), ref titamountVelocity, 0.1f);
        }

        else
        {
            tiltamountsideways = Mathf.SmoothDamp(tiltamountsideways, 0, ref titamountVelocity, 0.1f);
        }


    }

    private AudioSource droneSound;
    void DroneSound()

    {
        droneSound.pitch = 1 + (droneFirst.velocity.magnitude / 100);

    }


    }
Existe t'il un moyen d'assigner mon joystick pour que cela fonctionne ?
Vroummmmmmm :lol: :twisted:

Répondre

Revenir vers « (C#) CSharp »