Trying to slow down a sphere controlled by the player, when there is no input from axis.
2 checks are made
1st is to check if the object is moving
2nd is to check if the player is inputting to axis
without input i would like the sphere to stop, sooner than it would natually as if there is a high friction level.
But unfortunally i havent found any way to add friction so i guess adding a force in the oposite direction is the way to go.
Suggestions ?
public float accelleration = 1;
public float decelleration = 1.5f;
public float newPos;
public float lastPos;
private float currentSpeed;
private float opposingForce;
void Update()
{
if (newPos != transform.position.x)
{
//Player is moving
//Debug.Log ("Moving ");
//check if player has let go
if(Input.GetAxis("Horizontal") == 0 Input.GetAxis("Vertical") == 0)
{
//Player is moving without imput
//Debug.Log ("No touching");
//slow down movement
currentSpeed = rigidbody.velocity;
opposingForce = -currentSpeed;
rigidbody.AddRelativeForce(opposingForce * decelleration);
}
}
}
No need for feeling stupid. The PhysX engine is quite complex. If you got other questions about the physics let me know maybe I can help I have some knowledge about PhysX, we used it in the game Switchball.
I was Fx programmer on that team but we all got involved in the Physics because it was under heavy development at the time we started to use it. (It was way before Nvidia bought the engine from Ageia who bought it from NovodeX in 2004, if I remember correctly). All the changes at that time made us to reballance and tweak the values over and over again. So the whole team got involved in that process.