- Home /
How to make a Hostage Rescue Mechanics. (Counter Strike)
Hi. I am new to Unity Coding (C#). I am working on a project where I am trying to learn the Game Mechanics. I am trying to learn the logic of the Hostage Rescue Scene from the famous Game: Counter Strike. Where the CTs rescue the Hostages to their Spawn Location, and then they disappear & print a message : "Hostage has been rescued."
I have made a NPC Cube that follows the Player Cube. I have set up a Trigger Event at the Rescue Location & attached a script to it that says : Hostage has been Rescued." But the Problem I am facing is the NPC Cube doesn't come inside the Trigger (Box Collider). It stays away from it maintaining a Distance. As I am new, I do not have any knowledge about Layers & how to ignore them or use them.
So can anybody please help me achieving this.
The NPC Script
public class NPCFollow : MonoBehaviour {
public GameObject NPC;
public GameObject Player;
public float FollowSpeed = 1;
public float TargetDistance;
public float AllowedDistance = 5;
public RaycastHit hit;
private Rigidbody rb = null;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
transform.LookAt(Player.transform);
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 10))
{
TargetDistance = hit.distance;
if(TargetDistance >= AllowedDistance)
{
Debug.DrawRay(transform.position, transform.forward * 10, Color.red);
transform.position = Vector3.MoveTowards(transform.position, Player.transform.position, FollowSpeed * Time.deltaTime);
//transform.position -= MalePlayer.transform.position;
}
}
} }
The Hostage Rescue Script (Attached to the Box Collider - with the Trigger set to Active) public class RescueHostage : MonoBehaviour {
public GameObject Player;
public GameObject NPC;
private void Start()
{
Debug.Log("Rescuse the Hostage!");
}
private void OnTriggerEnter(Collider other)
{
if(other.name == "Hostage")
{
Debug.Log("Hostage Rescued.");
}
} }
Your answer

Follow this Question
Related Questions
Capturing a point 2 Answers
Detecting collision on start in my building system 0 Answers
Trigger Spawning? 1 Answer
OnTriggerEnter and GUIText problem 0 Answers
Raycast from inside an object 2 Answers