Unity Spain

Post Antiguos => General (Antiguo) => Mensaje iniciado por: ochoag en Mayo 05, 2016, 10:22:56 PM

Título: ¿Como puedo inclinar una nave usando el joystick?
Publicado por: ochoag en Mayo 05, 2016, 10:22:56 PM
Hola estoy intentando poder inclinar una nave con el joystick pero no he podido. ¿como podría hacerlo? si me pudieran ayudar porfavor se los agradecería mucho.Este es el codigo que me funciona sin el joystick:
     
using UnityEngine;
using System.Collections;
 
public class PlayerController2 : MonoBehaviour
{
    public float speed;
    public float tilt;
   
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
     
        Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);
        GetComponent<Rigidbody>().velocity = movement * speed;
 
        GetComponent<Rigidbody>().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
    }
}
 
pero aqui muevo la nave con el joystick:
using UnityEngine;
using System.Collections;
using UnitySampleAssets.CrossPlatformInput;
public class MoverNave : MonoBehaviour
{
    float sense = 5;
    public float speed;
   
 
    // Use this for initialization
    void Start()
    {
     
    }
    // Update is called once per frame
    void Update()
    {
        transform.Translate(new Vector3(0, CrossPlatformInputManager.GetAxis("Vertical")) * Time.deltaTime * speed);
        float y = CrossPlatformInputManager.GetAxis("Mouse Y") * sense;
        transform.Rotate(0, y, 0);
        transform.Translate(new Vector3(CrossPlatformInputManager.GetAxis("Horizontal"), 0) * Time.deltaTime * speed);
        float x = CrossPlatformInputManager.GetAxis("Mouse X") * sense;
        transform.Rotate(x, 0, 0);
   
 
    }
 
}
    }
 
}
 
Título: ¿Como puedo inclinar una nave usando el joystick?
Publicado por: farenhai en Mayo 06, 2016, 12:33:16 PM
A mí me funciona el primer código sin tocarle una coma (se mueve horroroso, pero no sé si es por mi ordenador -estoy en uno diferente al habitual-) 1 ¿Has comprobado que el Edit/Project Settings/Input está bien configurado?2) ¿Le has añadido suficiente velocidad? Prueba a aumentar mucho las variables speed y tilt Por defecto, estos valores los tienes en cero, con lo que es normal que no se mueva...