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 Michael 16 · Feb 10, 2011 at 01:32 PM · animationaicharacterenemyai

Boxing character and AI enemys

I have a third person (based on TornadoTwins tutorial) that can walk, rotate and shoot fire balls. On one point in my game he lossing hes ability to shoot so he have to use he's hands to fight, like boxing. how do I animate him that it will look like he hits the enemys (3 hits) and the enemys will seems like they being hit by me?

here is my character script:

//Walking 

var speed = 20.0;

var rotateSpeed = 4.0;

//Shooting var bullitPrefab:Transform;

//Dying private var dead = false;

//Getting hit var tumbleSpeed = 800; var decreaseTime = 0.01; var decayTime = 0.01; static var gotHit = false; private var backup = [tumbleSpeed, decreaseTime, decayTime];

function LateUpdate() { if (gotHit) { if(tumbleSpeed < 1) { //we're not hit anymore... reset & get back in the game! tumbleSpeed = backup[0]; decreaseTime = backup[1]; decayTime = backup[2]; gotHit = false; } else { //we're hit! Spin our character around transform.Rotate(0, tumbleSpeed * Time.deltaTime, 0, Space.World); tumbleSpeed = tumbleSpeed-decreaseTime; decreaseTime += decayTime; } } }

//function OnControllerColliderHit(hit : ControllerColliderHit) function OnTriggerEnter( hit : Collider ) { if(hit.gameObject.tag == "enemyProjectile") { dead = true; //substract life here HealthControl.LIVES -= 1; gotHit = true; Destroy(hit.gameObject); }

  if(hit.gameObject.tag == "HP_Capsule") //extra Lives
  {
      if(HealthControl.LIVES &gt;=3)
      {
          HealthControl.LIVES +=1;
          Destroy(hit.gameObject);
      }
      else
      {
          HealthControl.LIVES = 3;
          Destroy(hit.gameObject);
      }
  }

}

function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

     var forward = transform.TransformDirection(Vector3.forward);
     var curSpeed = speed * Input.GetAxis ("Vertical");

     controller.SimpleMove(forward * curSpeed);

     //Shooting!
     if(Input.GetButtonDown("Jump"))
     {
          var bullit = Instantiate(bullitPrefab, transform.Find("SpawnPointB1").transform.position, Quaternion.identity);
          bullit.tag = "bobProjectile";
          bullit.rigidbody.AddForce(transform.forward * 5000);
     }
  }

@script RequireComponent(CharacterController)

Another question i have is how to make the enemys follow after me and rotate? how to make an AI enemy?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by FLASHDENMARK · Feb 10, 2011 at 02:11 PM

var distance; var target : Transform; var lookAtDistance = 15.0; var attackRange = 10.0; var moveSpeed = 5.0; var damping = 6.0; private var isItAttacking = false;

 function Update () 
 {
 distance = Vector3.Distance(target.position, transform.position);

 if(distance &lt; lookAtDistance)
 {
 isItAttacking = false;
 renderer.material.color = Color.yellow;
 lookAt ();
 }   
 if(distance &gt; lookAtDistance)
 {
 renderer.material.color = Color.green; 
 }
 if(distance &lt; attackRange)
 {
 attack ();
 }
 if(isItAttacking)
 {
 renderer.material.color = Color.red;
 }

}

function lookAt () { var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); }

function attack () { isItAttacking = true; renderer.material.color = Color.red;

 transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);

}

Here is a VERY basic AI. Just remember to drag the target you want the AI to follow in the inspector. When you come in a certan range it will look at you. If you get even closer it will attack you. I dont know if you can use this or not.

Tell me if there is something you wanna know and if you can use this.

Happy to help :)

Comment
Add comment · Show 4 · 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 Michael 16 · Feb 10, 2011 at 02:39 PM 0
Share

thx. (wow, that answer was fast...).I'll try it. I asked about the animate of the "Boxing Charecter", can you help me with that?

avatar image Michael 16 · Feb 10, 2011 at 02:57 PM 0
Share

THAT-AWSO$$anonymous$$E!!! That AI works great! thx so much!

avatar image FLASHDENMARK · Feb 10, 2011 at 03:25 PM 0
Share

That is great! :) I am afraid that i can not help you further, since that is not so much my thing :(. Sorry, but good luck with your project ;)

avatar image Mathias · Feb 15, 2011 at 04:11 PM 0
Share

This is really cool. Who is the man? You are. THAN$$anonymous$$ YOU :)

avatar image
0

Answer by anamzara · Jan 16, 2018 at 02:26 PM

thx. (wow, that answer was fast...).I'll try it. I asked about the animate of the "Boxing Charecter", can you help me with that? max muay thai thai tube baiyoke sky buffet Tokyo sky tree universal studios singapore Australia zoo

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

1 Person is following this question.

avatar image

Related Questions

Character Animation won't work with FPS scripts 1 Answer

Simple AI and Animation 2 Answers

How to handle multiple animation variants 1 Answer

Camera shall stay on face while animating a Character 0 Answers

Character Pipeline 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