I want to first of all say this place is awesome, iv always found answers i wanted but i think i ran out of luck this time and i have to be specific with my question. I am creating an infinite run game. I want my characters speed to increase with time spent playing. I am currently multiplying by a variable i increment in a function. My problem is how do i make it stop at a certain speed. This is because i discovered that at a certain speed, the ontrigger function i use in loading my scenes in front of character fails. So i decided to stop it at a particular speed. i tried using the “if” statement but it doesnt seem to wrk for me. Here is my code
var speed : float = 3.0;
static var viewincrease:int;
static var increase:int=1;
static var totalIncrease:int=1;
private var jumpSpeed : float = 50.0;
private var gravity : float = 50.0;
private var moveDirection : Vector3 = Vector3.zero;
function increaseSpeed(){
increase +=50;
}
InvokeRepeating("increaseSpeed",3,3);
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
Debug.Log(totalIncrease);
totalIncrease = -120 - increase;
moveDirection = Vector3(Input.GetAxis("Horizontal")* speed , 0, totalIncrease );
if (totalIncrease>=300){
totalIncrease=300;
}
// Debug.Log(viewincrease);
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
Please forgive my rough code writing, im kinda new to programming. And forget about my minus sign also. I know why its like that. I just need help figuring this out. I will be immensely greatful. Or if someone can suggest a better way for me to instantiate scenes.i tried time, but the whole delta time/frame rate thing made it fail constantly. Thanks alot