Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Hello guys! I want to slow down the player's speed when i let up my left mouse button. I tried everything but nothing work. Please help! Thanks.

$
0
0
**Here is my code so far** private Rigidbody2D rB; private Vector2 mousePos; private float speed = -10.0f; private bool canSlow; // Start is called before the first frame update void Start() { rB = GetComponent(); canSlow = false; } // Update is called once per frame void Update() { if (canSlow) { speed += 0.1f; } mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Input.GetMouseButton(0)) // If pressing the mouse { Vector2 lookDir = mousePos - rB.position; float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f; rB.rotation = angle; } if (Input.GetMouseButtonUp(0)) // If let up the mouse { canSlow = true; rB.AddForce(transform.up * speed * Time.deltaTime, ForceMode2D.Impulse); } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>