Hi,
I’m trying to figure out how can i move my character to some fixed height,for example if my character position is at 10 and i want to lift him in gradually to let say 15.
this is what i’m doing:
If you’re using the standard FPS Controller, you can make a “jet pack” effect by setting a vertical velocity. In this script, when you press F the character starts to get height like moved by a jet pack; you can’t control directions fully while it’s going up, but as soon as you release the F key the control keys work as usual:
var cMotor: CharacterMotor;
function Start(){
cMotor = GetComponent(CharacterMotor);
}
function FixedUpdate(){
if (Input.GetKey("f")){
cMotor.SetVelocity(Vector3.up*1.5); // vert velocity = 1.5
}
}
It’s because you position towards the current transforms position +5 every frame. You have to store the Y-position first and transform against that instead.
var nextHeight : float = 10.0;
function setNextHeight (object : Transform) {
nextHeight = object.transform.position.y + 5;
}
Call the function on a given event (could be a trigger) with:
There are a few ways to do this. You could turn it into a coroutine in order to give you a large amount of control over how fast it moves, by what amount and when it stops. A simpler or faster way though would be to put an if statement in to stop the code for the character rising. Something like: