Boost Effect

I’ve got a gate that when the player goes through, it boosts in s certain direction (in this case, up). How do I do that cool boost effect without anything like AddForce or without it having a teleporter effect like I have just done:

// Make a Speed Effect
function OnTriggerEnter (other : Collider) {

print (“fast”);
other.gameObject.transform.position.y=other.gameObject.transform.position.y+10;

}

I want it like when you go through the gate it boosts you up.

1 Answer

1

Here is a simple version:

MovementWithBoost.js
var speed:float = 5.0f;

function Update(){
   
   transform.position.x += speed*Time.deltaTime*Input.GetAxis("Horizontal");
   while(speed > 5)speed-=Time.deltaTime;
}

Door.js

function OnTriggerEnter(col:Collider){
   var script:MovementWithBoost = col.gameObject.GetComponent(MovementWithBoost) as MovementWithBoost;
   if(script != null)
       script.speed = 10;
}

See if that does it. At least that should get you started. You may want to tweak value as your boost is about to decrease over 10 seconds.
If you use something like:

if(boost > 0)boost-=Time.deltaTime*boostDown;

you can reduce the period of boost but keep your boost high enough to be significant, it will just decrease faster (if boostDown is positif!!)

EDIT: The first script goes on any moving object you want to be able to be boost. The second goes ow on the door. When something collides with the door, the script checks if the object has the script. If not then script is null and the boost is not applied. If the object has one then the boost is applied.

EDIT AGAIN:
I modified the script again to add the input.

Haha thanks but, The problem is, if I add it to the gate, the gate moves forward. I want it so that I can add the script on a gate and I have variables which I can individually edit so that if anything touches the gate, it will be boosted in my variable direction.

You should not control your guy from the door script. That is just not logical. With the input that may fix a little your teleporting issue.