Knockback along curved surface.

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 );

And codes to simulate planetary gravity while moving in Update.

if ( !Physics.Raycast ( transform.position, -transform.up,  1.1 ) )
    ground = 0;
    faux += ( transform.position - ).normalized * -0.5 * Time.deltaTime; //apply gravity
    controller.Move ( faux );
	ground = 1;
    faux =; // reset gravity

QuaternionRotation = Quaternion.FromToRotation ( transform.up, ( transform.position - ).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.

the first thing that comes to mind is that you could first calculate the knock back force on a given frame, and make sure that it’s clamped within a certain velocity so that it doesn’t escape the planetary gravity. Because what you’ve described is essentially what should happen… if gravity is not strong enough to counteract the thrust, you should be able to shoot something right out of orbit… basic rocketry :wink:

But yeah, if you clamp that velocity per frame, it would do the trick. it might look strange, however- since it wouldn’t necessarily have the same ‘force’ to it.

The only other thing I can suggest is to increase the gravity that you’re applying based on the knockback velocity… that way if the force is too strong, you increase gravity to counteract it.