Hi
I want my gameObject to change animation, changing with the direction that is going.
The world 3d with objects 2d
I’m trying with velocity unsuccessfully
is working:
The monster follows the target until it gets close.
help me
my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class controleWyvern : MonoBehaviour
{
public Animator wyvern;
public Rigidbody myBody;
Transform alvo;
float velocidade = 5f, distancia = 20;
bool alvoEncontrado = false;
// Use this for initialization
void Start()
{
alvo = GameObject.FindGameObjectWithTag("Player").transform;
myBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Vector3.Distance(transform.position, alvo.position) > distancia)
{
alvoEncontrado = false;
}
else
{
alvoEncontrado = true;
velocidade = 5;
if (distancia / 2 > Vector3.Distance(transform.position, alvo.position))
{
velocidade = 0;
}
}
if (alvoEncontrado)
{
transform.position = Vector3.MoveTowards(transform.position, alvo.position, velocidade*Time.deltaTime);
}
//here is not working \/\/\/\/\/
if (myBody.velocity.z > 0)
{
wyvern.SetBool ("runU", true);
wyvern.SetBool ("runD", false);
wyvern.SetBool ("runL", false);
wyvern.SetBool ("runR", false);
}
if(myBody.velocity.z < 0)
{
wyvern.SetBool ("runU", false);
wyvern.SetBool ("runD", true);
wyvern.SetBool ("runL", false);
wyvern.SetBool ("runR", false);
}
if (myBody.velocity.x > 0)
{
wyvern.SetBool ("runU", false);
wyvern.SetBool ("runD", false);
wyvern.SetBool ("runL", true);
wyvern.SetBool ("runR", false);
}
if(myBody.velocity.x < 0)
{
wyvern.SetBool ("runU", false);
wyvern.SetBool ("runD", false);
wyvern.SetBool ("runL", false);
wyvern.SetBool ("runR", true);
}
}
}