I am currently using a SlamBack function to knock my avatar back.
function SlamBack ( slamDistance : Vector3 )
{
var controller : CharacterController = GetComponent(CharacterController);
var slamTime = Time.time;
while ( slamTime + 0.5 > Time.time )
{
controller.Move ( slamDistance * ( slamTime + 0.5 - Time.time ) / 0.5 * Time.deltaTime );
yield;
}
}
And codes to simulate planetary gravity while moving in Update.
if ( !Physics.Raycast ( transform.position, -transform.up, 1.1 ) )
{
ground = 0;
faux += ( transform.position - Vector3.zero ).normalized * -0.5 * Time.deltaTime; //apply gravity
controller.Move ( faux );
}
else
{
ground = 1;
faux = Vector3.zero; // reset gravity
}
QuaternionRotation = Quaternion.FromToRotation ( transform.up, ( transform.position - Vector3.zero ).normalized );
transform.rotation = QuaternionRotation * transform.rotation;
The end result i get when player gets knocked back is, it will move in a straight line backwards, leaving him off the curved planet surface, then dropping down from the gravity.
I was wondering if I can fine tune it so that it gets knocked back along the surface instead.
Will appreciate any tips, thanks.