Hit Log = Current Speed Returns to Start

Hey guys, I’m back once again. I’m not able to get this simple operation to work correctly so that whenever my player gameObject (a horse) touches a log at no matter what speed it’s at upon collision, the speed reverts back to start thus having to build the momentum once again. Below is the script to make the environment scroll (the horse is stationary in one spot) for class “scrollTerrain”:

var topSpeed = 20.0;
var minSpeed = 1.5;
var currentSpeed : float;
var acceleration : float = 5.0;

function Start () {
currentSpeed = minSpeed;
}

function FixedUpdate (){
currentSpeed = Mathf.Clamp(Time.time, minSpeed, topSpeed);
}

function Update () {
currentSpeed += Time.deltaTime * acceleration;
transform.Translate(-currentSpeed * Time.deltaTime, 0, 0);
}

And for the log at class “loghit”, I have this script:

var spdDown : float;

function Start () {

}

function Update () {

}

function OnTriggerEnter(other : Collider){

GameObject.FindObjectOfType(scrollTerrain).currentSpeed = spdDown;
	spdDown = 1.5;
}

It never wants to change the current speed back to 1.5 after hitting the log (and any other gameObject that collides with it in the future). What am I doing wrong?

you can’t assign the current speed to spddown BEFORE you assign the value of spddown.

you did that.

Move the spddown = 1.5 to above the findobject instead of below.

Right now the speed is the default value (not sure what that is)

debug.log(spddown) to see what it is if you want. put it before you assign the value.