Hi everyone!
I still working on my bots. On this case I have the problem that the bots after destroy his target, it stop move.
I explain: The bots must move in the map from one target to another (like way points)and when they touch one target, it must disappear. In this way, the targets act like “food”, and when a bot touch the “food”, it disappear and the bot going to the next one, but the problem come when the bot set a target and “devour” it, the bot stop move and the editor give me a error saying that the transform has been destroyed.
I don’t know if I explained well, but I want this:
-That when the bot “devour” a target, the bot go to the next one.
-Each time that I start the play mode, the bot go to a certain target, while all targets have the same tag. If it’s not too much to ask, how I can make that the bot go to a random target each time that I start the play mode?
I’m trying to make this for two months and I cannot do it, that is why I ask to the community. Thanks.
There is my bot script:
using UnityEngine;
using System.Collections;
public class bot_profile : MonoBehaviour
{
public string Name = "botname";
public string Aggressivity; // Bot Difficulty | passive | normal | hostile |
public float BotMoveSpeed; // Bot movement speed
public float BotRotationSpeed;
public static float BotCurrentMass = 10f; // Bot mass
public static float BotCellSize = 0.5f;
public float MaxDistance;
private GameObject bbody;
public Transform food_target;
private Transform myTransform;
void Awake()
{
myTransform = transform;
}
void Start()
{
bbody = GameObject.FindGameObjectWithTag("bot");
food_target = GameObject.FindWithTag("food").transform;
}
void Update()
{
bbody.transform.localScale = new Vector3(BotCellSize, BotCellSize, BotCellSize);
if (Aggressivity == "passive")
{
Vector3 dir = food_target.position - myTransform.position;
dir.z = 0.0f;
if (dir != Vector3.zero)
{
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.FromToRotation(Vector3.right, dir), BotRotationSpeed * Time.deltaTime);
}
myTransform.position += (food_target.position - myTransform.position).normalized * BotMoveSpeed * Time.deltaTime;
}
}
void OnTriggerEnter2D(Collider2D tfood)
{
if(tfood.gameObject.tag == "food")
{
BotCurrentMass += 1;
BotCellSize += 0.015f;
Destroy(tfood.gameObject);
}
}
}