Hello Unity3D.I have a question about character controllers.How can i make it that when my rigidbody projectile it pushes the character controller on the z axis or on the y axis?I have seen tutorials on how to do it but none of the seem to work with the character controller just the capsule collider.If anyone knows how i can push a character controller with a rigidbody.Can you please tell me how?
var mass: float = 3.0; // the lower the mass, the higher the impact
var hitForce: float = 2.5; // impact "force" when hit by rigidbody
var player: GameObject;
private var impact = Vector3.zero; // character momentum
private var character: CharacterController;
function Start(){
character = GetComponent(CharacterController);
}
function AddImpact(force: Vector3){
var dir = force.normalized;
dir.z = 0.5; // add some velocity upwards - it's cooler this way
impact += dir.normalized * force.magnitude / mass;
}
function Update(){
if (impact.magnitude > 0.2){ // if momentum > 0.2...
character.Move(impact * Time.deltaTime); // move character
}
// impact vanishes to zero over time
impact = Vector3.Lerp(impact, Vector3.zero, 5*Time.deltaTime);
}
function OnCollisionEnter (col: Collision){ // collision adds impact
AddImpact(col.relativeVelocity * hitForce);
if(col.gameObject.tag == "Dummy"&&player.animation.IsPlaying("Astral_Kick_Barrage_Start")){
col.transform.gameObject.animation.Play ("Hit_Flying");
}
}