1

I have written a simple game in Unity and I need help with some simple AI for enemies.

I have three GameObjects: Background,Player, and Enemy. All these objects have some sprites,rigidBodies etc. and Background contains Box/Circle Colliders. Player can move by pressing W/S/A/D. I need simple script in JS to allow Enemies to follow the Player (with path-finding). I tried something like this, but something has been wrong:

var agent: NavMeshAgent = GetComponent.<NavMeshAgent>(); agent.SetDestination(targetPoint); 

nothing happens...

Any help please?

1 Answer 1

1

Here is a very basic snippet that I have used in enemy movement which I placed into the Update() function of a movement script (Mind the C#):

Vector3 direction = Vector3.Normalize(transform.position - destination.position); transform.position = Vector3.MoveTowards(transform.position, destination.position, moveSpeed * Time.deltaTime); 

I hope it can help in getting your enemies to move around!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.