Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Giving life to enemy ai

Discussion in 'Getting Started' started by badassgamer, Jul 21, 2015.

  1. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    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?
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    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.
     
    badassgamer likes this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    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!
     
  4. james_m_russell

    james_m_russell

    Joined:
    Jun 2, 2015
    Posts:
    25
    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.
     
    badassgamer likes this.
  5. Ness

    Ness

    Joined:
    Oct 1, 2012
    Posts:
    182
    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.
     
    Last edited: Jul 21, 2015
    badassgamer likes this.
  6. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    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
     
  7. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Most of the coding in 2d is similar to 3d with the obvious differences that thinking & playing in 3d brings
     
    badassgamer likes this.
  8. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    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
     
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    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!
     
  10. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    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?
     
  11. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    http://unity3d.com/learn

    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.
     
    badassgamer likes this.
  12. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Correct.
     
    badassgamer likes this.
  13. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    but i already finishied everything they thought in roll-a-ball . but now iam doing more than that like adding enemies, music etc
     
    tedthebug likes this.
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Good for you! That's the best way to learn.
     
  15. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    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
     
  16. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    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.
     
    badassgamer likes this.
  17. badassgamer

    badassgamer

    Joined:
    Apr 26, 2015
    Posts:
    140
    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
     
  18. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    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