Making an Al Preform A task

OK, I’m not much of a programmer, more of a level Builder, But me and friend have decided to make a serious game. Which would be the classic Nazi Zombies, now as childish and stupid as it may seem, it was just something which we both new that we would not get bored when building it, so if anyone has ever played Nazi zombies or saw it, you would see that, in order for the zombies to get into the building they would have to got to a window and smash of the planks of wood and if the planks have already been smashed off and not repaired by the player, the zombie will simply clime in and attack the player. So how can I make the AL got to the window destroy it, clime in and attack the player?

Sorry about the length of the post, had to make sure that there was some background information.

Sean Hall

I think you will want to look at pooling (pools of zombies), triggers (triggers can be your windows) and those triggers can have states, as in window is destroyed, or window is fully built. If window fully built, you are good, you got some protection for a while. If the window is destroyed, the zombie has the ability to climb right thru unobstructed.

I under the concept Of pooling and triggers, but not how to implement them into a script to make the zombies/AL to do the actions, like I said, I’m more of a level Builder than a programmer, but I’m ready to learn. Do you have an suggestion on any components or scripts, or even a tutorial I could look at, because believe me I have been looking everywhere on Google.

Sean Hall

Not really,
But just the concept.

So for instance, beyond the actual things like animations and stuff, what you need to underrstand is…

var state : int;

as such you can make
if(state == 1)
windowDestroyed;
if(state == 2)
windowNotDestroyed();

as such, if state == 2, then zombie must spend more time in the trigger.
Perhaps that could be it, the longer the time spent in the trigger by a zombie, the damage of the window increases.
If you hit a certain damage level, the window is destroyed and yo switch to state 1.
Now, since we are at state 1, give the zombie the instruction to climb thru.

Yes, I understand now how to control when the AL goes though the window, but not everything else, that’s the thing. What I really need to know is how to make the zombie destroy the window, when the int is set to 0 and then when the damage gets to 100% set the int to 1, to make the zombie go inside.

I would just make it so that if, enterTrigger, if state == notDestroyed
if on stay in trigger, beginToDestroyWindow()
beginToDestroyWindow()
{could be something like hitWindow, cause 1Pt damage}
since the is called as long as the zombie stays in window, the idea is that the window will continue to take damage.

You must have previously set a damage limit to the window, so if the zombie hits the window 100 times… window is destroyed. And thus, state now equals windowDestroyed. Now, zombie can climb thru window.

So the code would look something like this:

function Start () {
var state : int;

if(state == 1)
windowDestroyed;
if(state == 2)
windowNotDestroyed();

BoxCollider(){ if {
if state == notDestroyed
if beginToDestroyWindow()
} else
Animation();
}
}

No.
You need to create a trigger object.

then atatch this script… this is rough…

var zombie : GameObject;
var windowState : int;
var windowDamageLimit : int;
function Start()
{
	windowState = 0; 
        windowDamageLimit =100;
}

function OnTriggerEnter (other : Collider) {
	
	if(other.name == "zombie")
	{	
		print("zombie entered trigger");
	}
}


function OnTriggerStay (other : Collider) {
	
	if(other.name == "zombie")
	{	
		if(windowState == 0)
    	{
    		windowDamage++;
    		if(windowDamage == windowDamageLimit)
    		windowState = 1;
    		return;
    	}
		if(windowState == 1)
    	{
    		zombieGoThruWindow();
    	}
	}
}

So just one more question, what would go on the end of the script to make the AL start to attack the player,so once it is though the window, how can I send it to the other script, I know this is basic stuff, but I need to learn. Also when zombieGoThruWindow(); is executed what code would be put on to make it run the animation of the zombie climbing though?

Sean Hall

well again,
I would use a trigger. Either on the player or the zombie…

and if thruTheWindow == true (zombie is in room)
now, it has the ability to attack the player.

so, if the zombie enters the players trigger, or if you have the player enter the zombies (tho I would only have one or the other, not both)
the zombie can attack. Why I put the initial var above (thruTheWindow) is because the zombie may enter the players trigger despite being outside. This prevents a weird bug.

On another note…
another way would be that the whole room is a trigger and once in that trigger, the zombie hunts down the player. You can do this by constantly checking the players position. You can update it every frame… every 1000 frames, its up to you. Then, if by luck, the zombie collides with the player, zombie attack. Again, applying damage to the player until the zombie or player is killed.

So the last suggestion, what is that called, so I could do some research on it.
Here’s a preview of my level.

It is called nothing.
It is just an object trigger, the size of the room. It is an option. The other option is a trigger on the player. If there is a trigger the size of the room, then the zombie will always be hunting the player. If the trigger is om the player, i would imagine that the trigger would be smaller than the room and thus the zombie, as i see it would have to enter the trigger. One method makes it more difficult for the zombie.

so which would you suggest and how should I go about it?

It depemds on what you want.
One is more of a hunt and capture, the other is more of once the zombie is on the room he is always able to track exactly ehere the player is.

Well hunt, but how would you do it and what components would you use? By the way the video shows the window they are breaking though, so what has to happen in the code it needs to execute a code to destroy one of the planks every time it hits the window.

Sean Hall

Well just thinking here, but i would then perhaps add the script to the zombie. That way the player must do his best to stay out of range of the zombie. That means write a triiger script, attactch it to the zombie. Make the collider, like aradar in size, meaning how far do you want the zombie to see.

As far as breaking the planks, youncould use what i gabe you but perhaps a 100, as what i have it set to now, does not break a window, but a plank. You could time this by adjusting the time it takes to break a plank against the time it takes to animate a zombie punch.

Aright, then. So the code above is for the window and all I need to do is add a box collider to the room and the zombie, so that when the zombie is in the room, he moves toward the player, and once the player is in the zombies box collider the zombie attacks the player. Yes.

What have you done besides making the current level? Have yoy done the FPS Tutorial from Unity? If not please complete, else everything renman3000 says will not make sense.

You see I am not a coder, but I can understand what he said from the first post, the rest is just him writing the script for you and you don’t understand what he is doing, why he is doing it and where should everything go.

So I suggest you do the tutorial (actually write and understand the code - it’s not diifcult, it’s robot english). Then you will understand where each script goes, how to play the right animation at the right time etc.
It’s useless if he writes the script and you don’t understand it, because if something isn’t working he won’t be there to fix it.

Right, I was looking at the PDF of the FPS Tutorial and came back to this post, I will start it and see if I can understand everything which is needed for me to get this done, Thank you both for the help.

If you are interested in doing something similar in C# though I recommend this tutorial http://forum.unity3d.com/threads/103421-Unity-Lesson-1-Draft