Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Brad Mance · Apr 16, 2011 at 07:39 PM · aienemyattack

Creating basic enemy animation and attacking

Hey Guys, I am trying to create a game for my class and I am having trouble with the enemy ai and animation. I have this model I found online, and I am trying to get it to attack the First Person player when it gets close to it, and to have it attack them and damage them. I also want to add animation so that when its invisible health-bar is depleted, it will act and it will fall down. Can any one tell me what I need to do in order to get it to do that? I don't have any other models of it expect its idle pose?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by psychentist · Apr 20, 2011 at 02:44 AM

okay, first of all, you need to get Blender. It's a free 3d modeling application with the ability to rig and animate your models, and it runs on just about anything. (windows, mac, linux) there are tons of tutorials on youtube on how to rig and animate.

next, about attacking.

lets use a zombie as an example.

so I make my zombie and give him a walk and attack animation. as far as A.I., the only thing he will do is walk up and attack. (he's a zombie, that's all he needs, right?)
ok so I import my zombie into unity. now copy the "smooth follow" script and in the copy, disable the Z axis of rotation, and attach the script to the zombie. he will now rotate accordingly to always "watch" the player. now I need to make 3 colliders. the first will be a rather large sphere collider. this will be the aggro detector. we tell it that whenever the player enters the aggro collider, attack him. if I remember correctly, each object can only have one collider, so each of these colliders will have to be attached to a child object. code for the aggro collider is as follows. (I've been out of the game for over a year now, so if this code needs tweaking, cut me some slack, okay?)

var zombiesSpeed : float = 2.5;

// we can adjust his speed later to fit the game's needs.

var isChasing : boolean = false;

animation["Walk"].wrapMode = WrapMode.Loop; function OnCollisionEnter(){ isChasing = true; animation.play ("Walk"); }

function OnCollisionExit(){ isChasing = false; animation.stop; }

function Update(){ if isChasing = true { transform.translate (zombiesSpeed,0,0); } }

okay, now the zombie will move forward whenever he is inside the aggro collider.(he's already rotating to face him, remember.) now we need to tell the zombie to attack whenever he is in range. that's where our next collider coms into play. this one is a box collider that just sits in front of the zombie, and is only big enough to encompass the reach of his arm. the principle is the same.

var isAttacking : boolean = false; animation["Attack"].wrapMode = WrapMode.Loop; function OnCollisionEnter (){ isAttacking = true; animation.play ("Attack"); }

function OnCollisionExit (){ isAttacking = false; animation.stop; }

so now the zombie will swing his arm at us, but at this point no ill effect will come of it. this is where our last collider comes into play. when you "rig" your model, you will essentially build a framework of "bones" for your mesh to follow. the last collider is a small sphere collider, which is made to be a child object of the zombies hand bone. now the code for that:

function OnCollisionEnter (other : collider){
if (other.tag == "Player" && attackCollider.isAttacking == true){
playerStatus.Life -= 1;
}
}

Okay, whew. now the player will take damage if he touches the zombie's hand, but only if the zombie is attacking. the line about playerStatus.Life -=1 is referring to another script called Player Status. this script needs a variable called Life. (duh) it can be applied to the player himself, or just an empty game object. it will need at least the following line of code

static var Life : integer = 5;

hope this helps, and good luck on your project.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Muzz 1 · Apr 16, 2011 at 09:07 PM

What you need to do: 1. You need to animate it. If you're asking such questions, then it may be better to get animated characters. 2. Next, you may want to write a cross-fade animation script. Check out the FPS tutorial - it's got a good example. 3. Now you need to do an AI script. Again, the FPS tutorial is your friend.

Just consider (no offence meant) -- Are you being too ambitious? Why not try and make something slightly simpler first?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Alex 21 · Apr 17, 2011 at 12:28 AM

You need a 3D modeler like Cheetah3d. You can import your model into cheat and create animations, and then, once created bring it back to unity.

You then call a script to play the animation when shooting.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Brad Mance · Apr 20, 2011 at 01:21 AM

I would try to make something simpler, but it is required though. Also, I am running vista on a non-mac labtop so cheetah3d is out of the question. I have an idea though. Could I possibly create a script to have particles shooting at my character when they are on view? If so, could you try to point me in the right direction.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Enemy behavior is not working after the enemy has spawned. 1 Answer

AI Script attached to Enemy and is Rotating around player 0 Answers

Enemy controller.move script slows down and speeds up. How to get it consistent? 0 Answers

Bug with my enemyAI 2 Answers

Monster Patrolling 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges