system
1
Hey there,
this problem sounds pretty easy to solve, but.... I don't get it.
I want to have a kind of loop that counts up the variable "acceleration" WHILE the space bar is pressed.And them when it is not pressed anymore I want to add a relative Force to the ball.
rigidbody.AddRelativeForce (Vector3.forward * acceleration);
So how do I write a counter, which counts while a button is pressed, and then, when it isn't anymore, it does whatever I want?
(For Example the Pinball game of windows)
It tried a while loop, which crashed my game several times...
var power = 0.0;
var forceToAdd = 5.0;
function Update ()
{
if(Input.GetButton("Jump"))
{
power += forceToAdd * Time.deltaTine;
}
if(Input.GetButtonUp("jump"))
{
rigidbody.AddRelativeForce(Vector3.forward * power);
}
}
Simple, adds to the power variable when the Jump button is down. When it is released we add force to the rigidbody.
Let me know if there are any errors :)
system
4
oh well there is small error
there is: power += forceToAdd * Time.deltaTine;
should be: power += forceToAdd * Time.deltaTime;
Time not Tine.
system
3
no errors, worked well :) , thx a lot