Hi, please understand me when i say I have spent hours browsing the forums and the internet looking for a solution to this and have so far resulted in nothing useful.
What I want to do is have a zombie which detect my player either through sight or sound. I had this working correctly using two empty gameobjects and attaching character controllers to them. However, due to them increasing/decreasing in size (to simulate noise and visibility) the player was thrown all over the place.
I replaced these empty game objects with spheres, both including standard sphere colliders. I then tagged one as “Sight” and one as “Sound” to simulate the different sound/sight effects when running or walking. My code however, refuses to pick up their tags and will only run when the player’s very tiny character controller makes contact with the zombie. I will paste my code here and hope to god one of you can help me stop smashing my head against a desk for the rest of the night.
#pragma strict
var Health : int = 100;
var theDetection : String;
function Update ()
{
if (Health <= 0)
{
Dead();
}
}
function ApplyDamage (Damage : int)
{
Health -= Damage;
}
function Dead ()
{
Destroy(gameObject);
}
function OnTriggerEnter (other : Collider)
{
theDetection = other.tag;
if (theDetection == ("Sight"))
{
Debug.Log("I see you.");
}
}
function HearDelay ()
{
if (theDetection == ("Sound"))
{
Debug.Log("I Hear you.");
}
}
Anyone got any answers at all? Im really stuck with this. Why is it picking up the tags of a character controller component but not the tag of a collider?
@Wampir888, just tried that and its still doing nothing im afraid. I cant understand why it would pick up the spheres if i add character controllers but not if i add sphere colliders instead. It doesnt make any sense at all.
I’m having trouble understanding how exactly your detecting it though? What do you mean “due to them increasing/decreasing in size” – so what is increasing/decreasing in size?
Just trying to understand what’s going on, so maybe I or someone else can help better. There could be something with the characters not having rigidbodies, and I think I remember seeing somewhere colliders without rigidbodies will actually not really do anything – but it was only under certain conditions I believe.
You’re right character controllers do behave differently than sphere colliders, as they have a different “set-up”.
Ok ill try my best to make this as clear as possible
Im making a game that is based on survival and zombies. The zombies will be able to hear/see you based on your movement. The code above tells them whether they have heard/saw you based on the speed at which you are travelling.
The way i determine how much noise the character is making and how visible they are is by attaching two separate sphere gameobjects to the player and changing their size depending on whether they are crouching, standing, walking or running. One sphere is named ‘Sight’ and has the tag ‘Sight’ which indicates that the zombie has spotted the player if the sphere makes contact with it (the zombie). This is the same for the sound sphere, but this is a little bigger to determine that he has heard you before spotting you.
The problem im having is that the code is not taking the tag from the game objects and passing it over to the zombie unless i attach a character controller to each sphere. If i attach a rigid body to the sphere or zombie there is still no difference. I cant understand why it can take the tag of a character controller but not a game object.
Does that make a little more sense?
I tried changing my code to make it detect the gameobjects rather than the character controller. Again, even with this strictly looking for objects with the tag “sight” or “sound” it still only detects the character controller! Its actually beginning to get on my nerves a lot more than it should lol.
function OnTriggerEnter(other : Collider)
{
sightObjects = GameObject.FindGameObjectsWithTag("Sight");
soundObjects = GameObject.FindGameObjectsWithTag("Sound");
if (sightObjects == GameObject.FindGameObjectsWithTag("Sight"))
{
Debug.Log("I see you!");
}
if (soundObjects == GameObject.FindGameObjectsWithTag("Sound"))
{
Debug.Log("I hear you!");
}
}
Thanks for the reply
Firstly Im coding in java and i really dont understand or want to use C# at all. Also, I have “istrigger” enabled and have also tried it disabled to no avail.
I may try adding the script to the sound/sight spheres and get them to detect the zombie. That way they can tell the zombie that it has detected me and it should come and kill me or whatever. Ill report back with whatever happens there.
Tried adding the character controller and rigidbody components to the zombie and then adding the script to the detection spheres. Still only picks it up if it contacts my character…why is it doing this. Is there seriously no one out there that can help me?