- Home /
hit.normal cube
hello, i have a character, which is controled by rigidbody. i want this to walk around a cube. the gravity works perfekt but the rotation of the character want to be equals to raycast's hit.normal, so that i can rotate the player around y axis. here the gravity script
function FixedUpdate(){
Colliders = Physics.OverlapSphere(transform.position, GravityZone.GetComponent("SphereCollider").radius*transform.localScale.y );
for(var i = 0; i<=Colliders.length-1; i++){
if(Colliders[i].gameObject.transform.rigidbody){
var hit : RaycastHit;
if(Physics.Raycast(Colliders[i].transform.position,(transform.position-Colliders[i].transform.position),hit)){
gravityUp = hit.normal;
Colliders[i].transform.rigidbody.AddForce(gravityUp*-9);
}
Debug.DrawRay(Colliders[i].transform.position,(transform.position-Colliders[i].transform.position),Color.red);
//gravityUp = Colliders[i].transform.position - hit.normal;
//gravityUp.Normalize();
//Colliders[i].transform.rigidbody.AddForce(gravityUp*-9);
if(Colliders[i].gameObject.tag=="Player"){
localUp = Colliders[i].gameObject.transform.up;
var q = Quaternion.FromToRotation(Vector3.up, hit.normal);
q = q * Colliders[i].gameObject.transform.rotation;
Colliders[i].gameObject.transform.rotation = //schneller hinstellen bei nähere distance
Quaternion.Slerp(Colliders[i].gameObject.transform.rotation, q, 8*Time.deltaTime);///(Vector3.Distance(transform.position,Colliders[i].transform.position)-transform.localScale.y/2));
localForward = Colliders[i].gameObject.transform.forward;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Turn Gravity on when collision occurs 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a cube fall without rigidbody 1 Answer
Gravity.cs help? 3 Answers
moving at certain circumstances 1 Answer