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 Blink · Oct 30, 2012 at 01:55 PM · animationenemywalkhealth

Enemy animation help?

So far my enemy follows me around and deals damage but Im having problems scripting its animations. My script doesn't seem to be doing anything but basically what I want it to do is play and idle animation until I come close to it and then for it to walk up to me and then attack me, can anyone help me out?

 animation.wrapMode = WrapMode.Loop;
 
 animation["idle"].speed = 0.5;
 
 animation["run"].speed = 2;
 
 animation["attack1"].speed = 1;
 
 var target : Transform;
 
 var dist = 15;

 
 function Awake () {
 
     myTransform = transform; 
 
 }
 
 
 
 function Start () {
 
     target = GameObject.FindWithTag("Player").transform; 
 
 }
 
 
 
 function Update () {
 
 
 
 
 
   
 
 
 
 
 
 if(dist < 2){
 
 animation.CrossFade("attack1");
 
 }
 
 
 
 if(dist > 2){
 
 animation.CrossFade("run");
 
 }
 
 
 
 if(dist > 15){
 
 animation.CrossFade("idle");
 
 }
 
 }
Comment
Add comment · Show 2
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 PAEvenson · Oct 30, 2012 at 02:14 PM 0
Share

you dont seem to be setting the distance anywhere...its always at 15 at the moment.

avatar image Blink · Oct 30, 2012 at 03:05 PM 0
Share

Yeah im not sure what im doing.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Montraydavis · Oct 30, 2012 at 04:26 PM

You need to set the distance !

 function Update ( )
 {
    dist = (transform.position - target.transform.position).sqrMagnitude ;
    dist *= dist ;
 }
Comment
Add comment · Show 5 · 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 Blink · Nov 01, 2012 at 02:07 PM 0
Share

This sort of works but my animations don't play how I would like them to. Is there a better way to script what I'm trying to achieve?

avatar image Montraydavis · Nov 01, 2012 at 02:37 PM 0
Share

Well, according the code you posted, I can't really see anything that would cause your animations to play. . . . Are you sure you are applying your animations to the correct Target, and that they are apart of the models bone structure . . .

I doubt this will change anything, but, try this for each of your animations that need to be looped . . .

 animation["animation names"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop ;

Please mark this as answered if this works for you. Thanks!

avatar image Blink · Nov 01, 2012 at 05:49 PM 0
Share

Nope this doesn't change anything, is there not a better way of coding the animations to play at certain distances?

avatar image Montraydavis · Nov 01, 2012 at 07:10 PM 0
Share

I am not really sure why this isn't working for you . . . I bet it has something to do with the animations. Try to preview the animations, and tell me if your model animates.

avatar image Blink · Nov 05, 2012 at 02:56 PM 0
Share

The animations all work fine, Im guessing it must be the script.

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I can't script enemy animation 0 Answers

Adding a counter? 1 Answer

Enemy attack/follow Player script? 4 Answers

Enemy Ragdoll help 1 Answer

Enemy Health Problem 2 Answers


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