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 mushiepang · Feb 28, 2012 at 07:03 PM · c#rtsenemiesunits

rts developement

OK so I'm making an rts, squad based game much like dawn of war 2. I have a camera and a click to move script down. I was wondering how Would I go about putting in a change between squads script? would I have to place a camera default on them to change to there view or simply stick with my free moving camera? I also have another question, How would I go about creating enemy squads that die when there hp reaches 0?(and if at certain points members of the squad dieing would be nice) please use c# to help if you could (only language other then unreal code I know).

Comment
Add comment · Show 6
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 mushiepang · Feb 29, 2012 at 01:16 AM 0
Share

i have made semi intelligent enemy ai that seek out the player in an rpg before aswell as health systems but never really got it right

avatar image syclamoth · Feb 29, 2012 at 01:48 AM 0
Share

Well, for starters I'm not really sure how 'squads that die when there hp reaches 0' is really a question, since that sentence alone is basically a pseudocode version of what you would need to write in order to achieve that anyway. I would keep the camera free-moving, with an option to 'focus' on a particular squad to temporarily lock the camera onto them.

As for the squad dying, why not just give each memeber individual HP values, and then calculate the seperately? There's no need to actually show the player this happening, $$anonymous$$d you, but it will make the whole experience more generally realistic.

avatar image mushiepang · Feb 29, 2012 at 02:33 AM 0
Share

Well I have just given them indavidual hp, great idea btw, but still I need to know what kinda of function would I need to ad to the code so that it triggers the death and stops them from moving?

avatar image syclamoth · Feb 29, 2012 at 03:45 AM 0
Share

Well, why not something like this?

 if(HP <= 0)
 {
    Destroy(gameObject);
 }

 void OnDestroy()
 {
    Instantiate(deadPrefab, transform.position, transform.rotation);
    mySquad$$anonymous$$er.RemoveDude(this);
 }

Then, make sure that each member of the squad has a reference to a 'controller' script, and the controllerscript has some way of addressing each 'alive' member. The 'RemoveDude' function should remove the reference to that member, so as to prevent null-reference-exceptions.

avatar image mushiepang · Feb 29, 2012 at 07:11 AM 0
Share

using UnityEngine;

using System.Collections;

public class EnemyAI : $$anonymous$$onoBehaviour {

 public Transform target;

 public int moveSpeed;

 public int rotationSpeed;

 public int maxdistance;

 

 private Transform myTransform;

 

 void Awake(){

     myTransform = transform;

 }





 void Start () {

     GameObject go = GameObject.FindGameObjectWithTag("Player");

     

     target = go.transform;

 

     maxdistance = 2;

 }

 



 void Update () {

     Debug.DrawLine(target.position, myTransform.position, Color.red); 

     



     myTransform****tation = Quaternion.Slerp(myTransform****tation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);

     

     if(Vector3.Distance(target.position, myTransform.position) > maxdistance){

     //$$anonymous$$ove towards target

     myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

 

     }

 }

     

}

Thats my ai script but it says that line 30 is wrong that EnemyAI.myTransform is a field when expecting a type, and i dont know what that means

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

My unit won't stop moving (RTS) 0 Answers

Enemies Cannot Be Selected After The First One Dies... 1 Answer

Creating a 'Screen Rect' with two Vector3s 1 Answer

unit selection issue 0 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