How to smooth/damp a movement?
Can you tell a newbie how to smooth/damp this script? What i'm trying to achieve is when i tap the screen to reverse gravity immediately and when i tap again vice versa but instead it takes couple of seconds to do it .Can you help me?
public GameObject playerObject=null;
public float moveSpeed;
Rigidbody2D player;
void Start () {
player = playerObject.GetComponent<Rigidbody2D> ();
}
void FixedUpdate () {
player.velocity = new Vector2 (moveSpeed,player.velocity.y);
for (int i = 0; i < Input.touchCount; i++)
{
Touch touch = Input.GetTouch (i);
if (touch.phase == TouchPhase.Ended && touch.tapCount == 1 )
{
Vector3 position = Camera.main.ScreenToWorldPoint (touch.position);
if(player.gravityScale==0.5f)
player.gravityScale=-0.5f;
else
player.gravityScale=0.5f;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to use damping? 0 Answers
SmoothDampAngle problem when the target angle is 90 - 270 degree 2 Answers
Changing gravity at the click of a button... 5 Answers
Want to set differnt gravity for differnt place in one project. 1 Answer
gravity shift 0 Answers