How to use damping?
Hey guys so im using 2D editor.So my object is falling and i've written a code that when i press the screen it reverses gravity.My issue is that while changing the gravity orientation it is "snapping" so i want to stop it by damping it using code?But i don't know how?
Comment
Can you tell me how to damp/smooth this script?
using UnityEngine; using System.Collections;
public class PlayerControls : $$anonymous$$onoBehaviour {
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;
}
}
}
}
I want when i press to reverse gravity to immeadetely reverse it but ins$$anonymous$$d it takes couples of seconds to do it.Can you help?
Your answer
Follow this Question
Related Questions
How to smooth/damp a movement? 0 Answers
Gravity not working 3 Answers
Having trouble rotating around transform.up 0 Answers
How to jump while gravity is reversed 2 Answers
Collisions and Jerkiness Unity 2D 1 Answer