ive tried alot of the Follow scripts here, and i mean alot, and i cant seem to get anything working correctly. does anyone have a script that will make a zombie run at my character while playing the Walk animation? and gravity affects it and everything? if someone had one thatd be great. thx for any help in advance.
Such a script should be fairly straightforward to write.
I can’t comment directly on the animation aspect, but regarding the basic behavior, here’s what I’d do:
-
Use the ‘character controller’ component, and use the SimpleMove() function for movement. (SimpleMove() takes a motion vector in the xz plane, and moves the character controller by that vector while automatically applying gravity.)
-
To compute the motion vector:
- Subtract the player position from the entity’s position.
- Normalize the result.
- Set the ‘y’ element to 0 (this step isn’t strictly necessary).
- Finally, use Quaternion.LookRotation(), with the motion vector as the argument, to orient the entity correctly.
If you try that (or one of the other ‘follow’ scripts you mentioned) and it doesn’t work for you, post your code here along with a description of how exactly it’s not working.
ok well the code im using right now works fairly well, it just needs a bit more somthing added.
var leader : Transform;
var follower : Transform;
var speed : float =5; // The speed of the follower
function Update(){
follower.LookAt(leader);
follower.Translate(speed*Vector3.forward*Time.deltaTime);
animation.Play("Walk");
}
i found this somewhere on the forum.
he follows and rotates toward me, however, if i would stand in place and let him walk up to me, he wouldnt stop when he got to me, he would start flying around in a 360 degree circle around me. the same thing would happen if i jumped past him or over him, he would rotate super fast. another thing is that he can fly or jump or jump at random times, and i dont want that to be possible. that only happens really when i go past him or he walks up to me tho.
i tried something like what you said, but he would start by heading in my general diretion but then not rotate toward me if i moved away, he would just keep going in the direction where i just started.
thx for helping tho!
Ah, I thought you said you hadn’t been able to get anything working correctly. But it sounds like what you’re actually looking for is to add new features to what you already have.
Do both the player and the zombie have colliders of some sort? Assuming they do, I would think that when the zombie reached the player, it would simply bump into the player and continue to walk ‘towards’ the player (but without getting anywhere).
As for rotating too quickly in certain circumstances, for that you’ll have to revise your code a bit. In short, you’ll want to have the zombie turn towards the player rather than ‘snapping’ immediately to its new orientation. This can be done using interpolation, or by applying a relative rotation to the left or right as appropriate. (The math behind this is fairly simply, but ask if you need help with it.)
You must not have been re-computing the direction vector correctly then. Anyway, the ‘look at’ method you’re using now is just as effective, so I’d stick with that.
You didnt put any code to do anything else, he is trying to move to your location (which obviously he cant).
Did anyone know the script to kill the zombie?
thanks.
Why necro 8 years old post, which such request? Thats proper zombie script. ^^