Giving life to enemy ai

I created an enemy model standing with weapon but without moving or doing anything so i want him to come and attack the player with mace or any melee weapon and also do some activities like eating etc so what are the procedure for doing this?

Your question is simple, but the answer is very broad and includes a lot of areas like scripting, mecanim, animation, triggers, physics probably, etc… If you can’t really narrow it down to something more specific, i would suggest that you start here.

1 Like

I would also suggest you start by deleting your humanoid weapon-wielding character, and put in its place something more like this.

This eliminates mechanim, animation, triggers, physics, etc., and lets you focus on just one thing: behavior. Write a script to make it go for the player. Then extend this so that it goes toward the player a while, then gets bored and does something else (goes in a random direction, goes toward a nearby piece of fruit, whatever). Then extend it so that if the player has a power-up, it flees the player, perhaps with some simple animation to indicate that it’s doing so. Then, when you’re really getting advanced, you can see about making it stick to the confines of its environment (not passing through walls for example).

Basically, if you can’t make Pac-Man, then you’re not going to be able to make TF3 or whatever high-resolution realistic 3D action shooter kids play these days. So give yourself a break, and start with something simple!

3 Likes

in the survival shooter tutorial, they go through an example, where the enemy’s attack the player based on distance, and navigate the level with a navmesh.

(it also goes through the basics of the animator). I’d go through that tutorial and see if it helps.

1 Like
  1. Use Find in start function to find the player.
  2. Add a sphere collider to an enemy that will serve as a sight/awarness sphere.
  3. Initiate enemy movement to the player position on trigger.

If you do this you should know how go further and script attacking etc.

1 Like

thank you all for reply and @ joestrout then i need to continue on my roll a ball game cause this enemy you mentioned does not suitable for 3D games with world surronded by mountains rivers etc lol and just asking is learning simple 2D make us learn 3D cause everything in 3D is so differnt. and thank you

Most of the coding in 2d is similar to 3d with the obvious differences that thinking & playing in 3d brings

1 Like

and also i have new question . now i left my 3D project for a while until i learn some basics so i started 2D roll a ball game . but i think it would be better to replace the ball with tiny character ( 2D) so i need change everything? like script etc

I can’t quite understand what you’re asking. But in Unity, there is not much difference between 2D and 3D. You can use 3D objects in a 2D game, or 2D objects in a 3D game. Mix and match however you like!

no i mean now my simple game has a ball as his main character ( player) but i think can i replace that ball with a 2D character without doing much change gam?

Do the tutorials here. They start off simple (roll a ball) & move onto harder stuff. They also give you all the assets to download that you will need.

1 Like

Correct.

1 Like

but i already finishied everything they thought in roll-a-ball . but now iam doing more than that like adding enemies, music etc

1 Like

Good for you! That’s the best way to learn.

thank you and so how long should i learn basics ? i asked this cause when i first started unity3d . i begun with basic tutorial and learned a lot except scripting and so i thought iam still no longer beginer so i moved to 3D projects but still people saying im beginer so i moved back to basics again

Just work up through the tutorials, they gradually get harder. Then start modifying them with what you’ve learnt. Learn particles, lighting & sound & go back & put them in. Then start making simple games on your own, it may be easier to just remake old style games like pong, space invaders etc & once they are working add to them. By copying older games you are testing your knowledge of putting it together without having to worry about making up your own game with mechanics, art etc. Then pick a mechanic & make your own game. It could be a shmup or a platformer with your own spin on them. Take incremental steps, learn something then try to use it to reinforce it, then move onto the next thing. You will eventually find you are making more & more complex games, but remember simple is often better.

1 Like

thank you for advice but simple 2D games are little harder for me than 3D games because it is diffcult to understand 2D concept . i can create 3D envoirment with mountains rivers in just minutes but it is hard to create 2D envoirment even thought i know in 3D we have to do lots of work

You can use 3d objects in 2d, just pay attention to the depth. You can still switch the editor to 3d to make sure 3d objects don’t stick to far forward. I’ve used a mix of 3d & sprites