CharacterController ,OnControllerColliderHit, push box

August 2, 2013   ·   0 Comments


function OnControllerColliderHit (hit : ControllerColliderHit )
{
    Debug.Log("OnControllerColliderHit");
    if(hit.gameObject.tag=="box"){
     //  Destroy(hit.gameObject);
     
       var body : Rigidbody = hit.collider.attachedRigidbody;
 
    // no rigidbody
    if (body == null || body.isKinematic) { return; }
 
    // We dont want to push objects below us
    if (hit.moveDirection.y < -0.3) { return; }
 
    // Calculate push direction from move direction,
    // we only push objects to the sides never up and down
    var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
 
    // If you know how fast your character is trying to move,
    // then you can also multiply the push velocity by that.
 
    // Apply the push
    body.velocity = pushDir * pushPower;
    
    
     
     
    }
//	Debug.DrawRay(hit.point, hit.normal);
	if (hit.moveDirection.y > 0.01) 
		return;
}
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon