Can someone help me with the Mathf.SmoothStep function.
I tried this to get an acceleration but it is not working.
var back = -5;
var rotationright = 10;
var rotationleft = -10;
var a;
function Update() {
if (Input.GetKey ("w")) {
a = Mathf.SmoothStep(0, 20, 10);
}
if (Input.GetKey ("w")) {
transform.Translate(0, 0, a * Time.deltaTime);
}
if (Input.GetKey ("s")) {
transform.Translate(0, 0, back * Time.deltaTime);
}
if (Input.GetKey ("a")) {
transform.Rotate(0, rotationleft * Time.deltaTime, 0);
}
if (Input.GetKey ("d")) {
transform.Rotate(0, rotationright * Time.deltaTime, 0);
}
}
Im not sure what exactly your after but a few notes about the Mathf.SmoothStep function:
The parameters are (start, end, value)
The value parameter may need to be defined between 0 and 1 inclusive
The value parameter needs to be a variable otherwise the function is always going to return the same value
The function will return values that ‘ease’ into and out of the start and end numbers, if you want to get the acceleration at any one point, you will need to calculate that manually.
great, thanks a lot, that works. :!:
I failed because i thought the ‘value’ from (start,end,value) means `time’ but like you told me it doesnt.
it works like below:
function Update() {
if (Input.GetKey ("w")) {
b = b + 0.01 ;
}
else
{
b =0.0;
}
a = Mathf.SmoothStep(0, 20, b);
if (Input.GetKey ("w")) {
transform.Translate(0, 0, a * Time.deltaTime);