hi
I’m trying to create a button when you press the button the sphere accelerate forward y keep going until the button is released, and keep going by the force and friction
this sphere also move with the character controller using these references
this what I have but don’t work
if (Input.GetButton(“Fire1”))
{
m_Rigidbody.AddForce(transform.forward * friction);
}
thanks
i create some variable rate, velocity, and final velocity also decelerate value zo this is the code now works
thanks to Acceleration script - Questions & Answers - Unity Discussions
still trouble with decelerate but okk
if (Input.GetButton("Fire1"))
{
//add to the current velocity according while accelerating
currentVelocity = currentVelocity + (accelerationRate * Time.deltaTime);
transform.Translate(currentVelocity, 0, 0);
}
else
if(currentVelocity > 0) {
currentVelocity = currentVelocity - (decelerationRate * Time.deltaTime);
transform.Translate(currentVelocity, 0, 0);
}
else {
transform.Translate(0, 0, 0);
}
currentVelocity = Mathf.Clamp(currentVelocity, initialVelocity, finalVelocity);
//propel the object forward
transform.Translate(currentVelocity, 0, 0);
}