Question by
root_2 · Jun 01, 2016 at 12:01 PM ·
multiplayerenemyaic# tutorial
Vector3.distance not working with UNET
hello, i have a little problem. I have an AI script that basically follow my player_prefab. It's working on solo player in MonoBehaviour.When i want to use it in multiplayer with UNET it's not working anymore. In Multi i instantiate my prefab or in solo i dont.when i print the Vector3.Distance it returns a distance changing itself or the my prefab isnt moving here the script.
using UnityEngine;
using System.Collections;
public class Enemy_AI : MonoBehaviour {
public Transform player;
public int speed = 200;
public int max_dist = 20;
public int min_dist = 10;
// Update is called once per frame
void Update () {
transform.LookAt(player);
var dist = Vector3.Distance(player.position, transform.position);
if (dist <= min_dist)
{
Debug.Log("the marble is in range of attack");
transform.position += transform.forward * speed * Time.deltaTime;
}
else
{
print("Distance to other: " + dist);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Tutorial on Button Mashers 0 Answers
Attack on Titan Multiplayer Problem 2 Answers
Customizing multi player 1 Answer
Keep list of gameobjects on server multiplayer 0 Answers
How to find local player gameobject? c# 3 Answers