- Home /
Sonic trampoline style with character controller(old one)
Any one knows how to do a trampoline (sonic style)with a character controller because i don't see any tutorials about it. i don't expect someone making me a script( if someone do a Great thanks) but i would like some directions.
Could you specify what a sonic style trampoline is? If it is a trampoline can't you make a Physics material for the trampoline with low friction?
Answer by ExplodingCookie · Mar 28, 2015 at 12:55 PM
Character Controllers move when the Move() function is called and a Vector3 is provided. This Vector3 can be calculated in a number of ways.
//How fast we move
var moveSpeed = 6.0;
//Gravity strength
var theGravity = 20.0
//How fast up or down we are going.
private var verticalSpeed = 0.0;
var controller : CharacterController;
//This is the vector the Move() function uses.
var finalMovement : Vector3;
function MovementUpdate () {
//Define the input we can get from a player
var vertical : String = "Vertical";
var horizontal : String = "Horizontal";
//Next we calculate the horizontal moment from the input values
var zxMovement = Vector3(horizontal, 0, vertical) * moveSpeed * Time.deltaTime;
//After this, we calculate gravity.
verticalSpeed -= theGravity * Time.deltaTime;
//But if the controller is on the ground, we set the vertical speed to zero to prevent dropping off the edge.
if(controller.isGrounded) {
verticalSpeed == 0;
}
//Now we calculate the final vector
finalMovement = zxMovement + Vector3(0, verticalSpeed, 0);
}
function Update () {
MovementUpdate();
controller.Move(finalMovement);
}
After this, a spring simply sets the vertical speed to something high.
Add this after the Update in the last script.
function SuperJump (strength : float) {
verticalSpeed = strength;
}
Then add a script to the object you want to do the launching that calls the SuperJump() and provides a strength.
var strength = 25.0;
function OnTriggerEnter(col : Collider) {
//Make sure to name the controller script "PlayerController" or else this won't work!
if(col.GetComponent(PlayerController)) {
col.SendMessage("SuperJump", strength);
}
}
This is just the basics. Hopefully I didn't typo something. xD. Anyway. Hope this helps!
euh i forgot to mention but im using the unity character controller with their built in script =( and i don´t know what to reference in the fpscontrollerscript.
Your answer
Follow this Question
Related Questions
Jumping not always work 2 Answers
I aren't able to jump. I find no mistake in the script 1 Answer
How to jump multiple times to mid air? 3 Answers
Trouble with spring platform 0 Answers
I cant make my Character jump. 0 Answers