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 mmangual83 · May 21, 2012 at 06:44 PM · ai

My Boss wont work

Hello All, I am writing a game application and I seem to be having some issues with my Boss. Here are the top 3 things wrong with it:

1- The boss doesnt chase the player. basically, every time the player gets withing range te boss doesnt chase him. This is what I got:

function SearchPlayer (position : Vector3) { // Run towards the player but after 3 seconds timeout and go back to Patroling var timeout = 3.0; while (timeout > 0.0) { MoveTowards(position);

     // We found the player
     if (CanSeeTarget ())
         return;

     timeout -= Time.deltaTime;
     yield;
 }

} function CanSeeTarget () : boolean { if (Vector3.Distance(transform.position, target.position) > attackRange) return false;

 var hit : RaycastHit;
 if (Physics.Linecast (transform.position, target.position, hit))
     return hit.transform == target;

 return false;

}

2 - The boss orientation with the player moves to the side every time it shoots so it never gets to the player. This is the code I got:

function Shoot () { // Start shoot animation animation.CrossFade("shoot", 0.3);

 // Wait until half the animation has played
 yield WaitForSeconds(delayShootTime);
 
 // Fire gun
 BroadcastMessage("Fire");
 
 // Wait for the rest of the animation to finish
 yield WaitForSeconds(animation["shoot"].length - delayShootTime);

}

function AttackPlayer () { var lastVisiblePlayerPosition = target.position; while (true) { if (CanSeeTarget ()) { // Target is dead - stop hunting if (target == null) return;

         // Target is too far away - give up    
         var distance = Vector3.Distance(transform.position, target.position);
         if (distance > shootRange * 3)
             return;
         
         lastVisiblePlayerPosition = target.position;
         if (distance > dontComeCloserRange)
             MoveTowards (lastVisiblePlayerPosition);
         else
             RotateTowards(lastVisiblePlayerPosition);

         var forward = transform.TransformDirection(Vector3.forward);
         var targetDirection = lastVisiblePlayerPosition - transform.position;
         targetDirection.y = 0;

         var angle = Vector3.Angle(targetDirection, forward);

         // Start shooting if close and play is in sight
         if (distance < shootRange && angle < shootAngle)
             yield StartCoroutine("Shoot");
     } else {
         yield StartCoroutine("SearchPlayer", lastVisiblePlayerPosition);
         // Player not visible anymore - stop attacking
         if (!CanSeeTarget ())
             return;
     }

     yield;
 }

} function RotateTowards (position : Vector3) { SendMessage("SetSpeed", 0.0);

 var direction = position - transform.position;
 direction.y = 0;
 if (direction.magnitude < 0.1)
     return;
 
 // Rotate towards the target
 transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime);
 transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);

}

3 - There I a feature I wanted to add to the boss called a force field which would show up every time the player shoots at it while the shield hit points are still greater than 0. But the things is that every time it shows up it appears next to the boss and not overing te boss. Tis is the code I got:

var Shield : GameObject; var shieldPoint = 100; var shieldMaxPoint = 100; var ShieldPosition : Vector3;

function Start() { Shield.renderer.enabled = false; } function OnCollisionEnter(collision : Collision) {

 if(collision.gameObject.tag == "Energy Bullet")
 {
     if(shieldPoint > 0)
     {
         Shield.transform.position = GameObject.Find("Boss").transform.position;
         
         Shield.renderer.enabled = true;
         if(Shield.renderer.enabled)
             shieldPoint -= 5;
     }
         hitPoints -= damage;
 }
 
         
 if (hitPoints <= 0.0)
 {
     Detonate();
     isDead = true;
 }

}

I hope to hear responses from you awesome users and thank you so much for your help!

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 HolBol · May 21, 2012 at 06:44 PM 0
Share

Can you please reformat your code properly? It would be a lot easier to read.

avatar image whydoidoit · May 21, 2012 at 10:55 PM 0
Share

Just a thought on problem 1 - is your physics line cast hitting the boss first and therefore always returning false when comparing the hit item to the target? You could fix that with some layer masking.

To reformat your code - select it and click the code (binary numbers) icon - or add 4 spaces before it on the line. I can't really make head or tail of it like it is.

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

[C#] Navmesh not detecting gameobjects in scene 0 Answers

Player Damage to enemy damage melee system 0 Answers

Unity AI/Enemy won't move towards target 0 Answers

Animator/Behaviour I want to get all the transitions of a state 0 Answers

AI keeps attacking objects that are not player. 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