add force for a character controller

hey, im trying to make a 2d platformer and im using a character controller.
so far the movement and the isGrounded and the slope limit is what makes me use a Character controller player and not a rigidbody.
but, when i want the player to get a knock back when hits enemy, i cant do it. because ill need to call the knock back movement every frame. so i will need to make another Vector2 and another Move() function. instead of just doing:
rigidbody.AddForce(x, y, 0)… which is just one frame calling and it do the job.
the player have many skills that adds forces which will end up in 30 move() functions…
is there any way to call AddForce from a rigidbody while im using Character Controller as my main movement tool?
or is there another way to do it with a Character Controller only?
because i cant get isGrounded properly on a rigidbody (if you touch a wall, it will think its a floor and let you jump)
also the slope limit is awesome and on a rigidbody i wont have thos things.
any help?

I would do something like this:

//this script goes on the player
public var speed : float = 15.0;
public var duration : float = 0.25;

private var controller : CharacterController;

function Start(){
	controller = GetComponent(CharacterController);
}

function Knockback(direction : Vector3){
	var startTime = Time.time;
	while(Time.time < (startTime + duration)){
		controller.SimpleMove(direction*speed);
		yield;
	}
}

im not an expert :slight_smile: but cant you just make an coroutine where you apply the force in a limted time and then call it under FixedUpdate/Update :slight_smile:

See above :wink:

as legend did… is valid…

what i personally do is to bake and interval you can imagine this is really easy and functional…

just create an empty
add an animation to it … this animation is the path that your character must to follow…
set your character as a child of that empty,
play the empty animation… what do we have? a moving character according the empty path :slight_smile:

thanks legend it works!
you have changed my way to script now lol

How to call this function ?
It give me error.
This is my script when player is hit by enemy ( script is on enemy weapon).

function OnTriggerEnter (hit : Collider)
{
if(hit.gameObject.tag == “Player”)
{
hit.gameObject.GetComponent(Knockback);
hit.SendMessage(“Knockback”, 100.0);
}

The error say that the value of send message Knockback are wrong…

in the function that is suppose to receive the send message for knock back, do you have a variable for the function like

function Knockbakc ( damage : float){
// your code here?

}

I second the OnTriggerEnter question. If I would like the player to be the one “knocking back” other character controller NPC’s would I achieve this with something like this?

It also works with a transform.Translate. Was trying to figure out something similar and this is what I ended up with that worked.

Code: