- Home /
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).
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
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.
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?
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.
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
Your answer
Follow this Question
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