var vspeed:float=0;
function FixedUpdate () {
rigidbody.velocity=transform.right*vspeed;
vspeed+=0.1;
Debug.Log(vspeed); //So i can monitor the values
}
now, I want the vspeed to decrease in steps of 0.1 each time I press the down key. How do I achieve that please.
Pls note:I'm a novice to programming
First up, modifying rigidbody.velocity directly is probably not what you want to do here. Are you relying on physics here? Is there any reason why you can’t just manually control the velocity by changing transform.position (adding currentVelocity to the current position every frame)? Directly changing rigidbody velocity values every frame messes with the physics, and I find that the engine really resists you trying things like that. Try something like this instead:
var velocity : Vector3 = Vector3.zero;
function Update() {
if(Input.GetKeyDown("down")){ //Please note this only happens when you press the button, for continuous inputs use Input.GetKey("down")
velocity -= transform.right * 0.1f;
}
velocity += transform.right * Time.deltaTime;
transform.position += velocity * Time.deltaTime; // This makes sure it's framerate-independent
}
This way, the velocity is controlled entirely programatically, and you don’t have to worry about physics glitches messing with your objects. Just out of interest, what are you actually trying to do here? I can’t quite work out why you would want to do this.