Would anyone help me translating this C# code to JS. i have tried but my skill’s in C# are not to brag about. heh
function AdjustToGravity() {
var origLayer : int = gameObject.layer;
gameObject.layer = 2;
var currentUp : Vector3 = transform.up;
//Vector3 gravityUp = (transform.position-gravityCenter).normalized;
var damping : float = Mathf.Clamp01(Time.deltaTime*5);
RaycastHit hit;
Vector3 desiredUp = Vector3.zero;
for (int i=0; i<8; i++) {
Vector3 rayStart =
transform.position
+ transform.up
+ Quaternion.AngleAxis(360*i/8.0f, transform.up)
* (transform.right*0.5f)
+ desiredVelocity*0.2f;
if ( Physics.Raycast(rayStart, transform.up*-2, out hit, 3.0f, groundLayers.value) ) {
desiredUp += hit.normal;
}
}
desiredUp = (currentUp+desiredUp).normalized;
Vector3 newUp = (currentUp+desiredUp*damping).normalized;
float angle = Vector3.Angle(currentUp,newUp);
if (angle>0.01) {
Vector3 axis = Vector3.Cross(currentUp,newUp).normalized;
Quaternion rot = Quaternion.AngleAxis(angle,axis);
transform.rotation = rot * transform.rotation;
}
gameObject.layer = origLayer;
}
had problem’s sticking the player to the ground and then i found this C# script in the locomotive demo, i think this is a good way to go…