- Home /
Object floating and going through walls/ground.
In my game I have a character that I want to follow the player, but the character(a zombie), both floats and can go through terrain, walls, the player etc. Here is the code that I have.
var PlayerLocation : Transform;
var AppliedGravity : float = 20;
var Speed : float = 5;
private var CurrentTransform : Transform;
private var Character : CharacterController;
function Start(){
CurrentTransform = transform;
Character = GetComponent(CharacterController);
}
function Update(){
if(CharlieDetect.EnemySee){
animation.Play("Walk");
transform.position = Vector3.MoveTowards(transform.position, PlayerLocation.transform.position, Speed);
transform.LookAt(PlayerLocation.transform);
}
else{
animation.Play("ArmatureAction");
}
}
Answer by cod · Sep 11, 2013 at 11:59 AM
just add a collider to your zombie
EDIT: i'd add a rigidbody to the zombie and move him with rigidbody.addforce rather than vector3.movetowards, as translating a object with collider and rigidbody modifying its position can make the collision seem weird and innatural
Hope this helps
Thanks for the help, it worked, but how do I make the character move forward on the local axis, not the global one?
well, if u are using a rigidbody just add
rigidbody.AddForce(transform.forward*_power)
where rigidbody is your zombie's rigidbody and _power is... the power u want to apply