How to force a player to jump?

I am using the FPS Controller that comes with Unity. I want the player to jump (out of their control) when something collides with them. I have everything in place except for going about coding the line of code that would force the jump.

In JavaScript is there away to access the character motor in another script to trigger the jump with no input from the player?

Thank you in advance!

Yes, you can modify the controller script and expose the method that triggers the jump (the one called when Space is pressed). Just use GetComponent on your FPS Controller to get the script with the method, and call it.

You can also directly modify the velocity vector of any gameobject, even if it isn’t the first person controller that comes with Unity or if it doesn’t have any method to trigger the jump. The line of code would look something like this :

rigidbody.velocity = new Vector3(rigidbody.velocity.x, jumpforce, rigidbody.velocity.z);

The jumpforce being a variable (preferably public) so that you can alter it later.