[Duvida] Controle de Terceira pessoa por JoyStick
3 participantes
Página 1 de 1
[Duvida] Controle de Terceira pessoa por JoyStick
Olá galera, estou usando dois scripts livres de terceiros, pra fazer um controle de um Trirth Person, mas em vez de o personagem andar, ele cai e rola :D :D, gostaria de saber o que eu tenho que mudar pra fazer funcionar kk.
Obrigado amigos, tenham um excelente final de tarde!
- Código:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public VirtualJoystick joystick;
public float speed = 150.0f;
private Rigidbody rigid;
private void Start()
{
rigid = GetComponent<Rigidbody>();
}
private void Update()
{
rigid.AddForce(joystick.InputDirection * speed * Time.deltaTime);
}
}
- Código:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
public class VirtualJoystick : MonoBehaviour, IDragHandler, IPointerUpHandler, IPointerDownHandler
{
public Image bgImg, jsImg;
public Vector3 InputDirection { set; get; }
private void Start()
{
bgImg = GetComponent<Image>();
jsImg = GetComponentsInChildren<Image>()[1];
InputDirection = Vector3.zero;
}
//EventSystems interfaces
public virtual void OnDrag(PointerEventData ped)
{
Vector2 pos = Vector2.zero;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle
( bgImg.rectTransform,
ped.position,
ped.pressEventCamera,
out pos))
{
pos.x = (pos.x / bgImg.rectTransform.sizeDelta.x);
pos.y = (pos.y / bgImg.rectTransform.sizeDelta.y);
float x = (bgImg.rectTransform.pivot.x == 1) ? pos.x * 2 + 1 : pos.x * 2 - 1;
float y = (bgImg.rectTransform.pivot.y == 1) ? pos.y * 2 + 1 : pos.y * 2 - 1;
InputDirection = new Vector3(x, 0, y);
InputDirection = (InputDirection.magnitude > 1) ? InputDirection.normalized : InputDirection;
jsImg.rectTransform.anchoredPosition = new Vector3(InputDirection.x * (bgImg.rectTransform.sizeDelta.x / 3)
, InputDirection.z * (bgImg.rectTransform.sizeDelta.y / 3));
}
}
public virtual void OnPointerDown(PointerEventData ped)
{
OnDrag(ped);
}
public virtual void OnPointerUp(PointerEventData ped)
{
InputDirection = Vector3.zero;
jsImg.rectTransform.anchoredPosition = Vector3.zero;
}
}
Obrigado amigos, tenham um excelente final de tarde!
gcs13- MembroAvançado
- PONTOS : 2417
REPUTAÇÃO : 29
Idade : 22
Respeito as regras :
Re: [Duvida] Controle de Terceira pessoa por JoyStick
Cai e Rola?
Os Eixos X e Z Estão Destravados?
Os Eixos X e Z Estão Destravados?
Magnatah- Instrutor
- PONTOS : 3339
REPUTAÇÃO : 208
Idade : 24
Áreas de atuação : Dєรєиvσlvєdσя Wєb(Fяσит-єиd), Blєиdєя, υиiтy, C#, ρнρ є Jαvαรcяiρт.
Respeito as regras :
Tópicos semelhantes
» Controle de câmera em primeira pessoa com um joystick virtual
» JOGO EM TERCEIRA PESSOA
» (Dúvida) Mirar em terceira pessoa.
» Personagem em terceira pessoa!
» Terceira Pessoa
» JOGO EM TERCEIRA PESSOA
» (Dúvida) Mirar em terceira pessoa.
» Personagem em terceira pessoa!
» Terceira Pessoa
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos