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

Unity 2D addforce problem

$
0
0
Hello, I am trying to move my character and I assigned AddForce to "d" but it just starts moving then it stops and I need to press key again to start moving. Here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class movement : MonoBehaviour { public Rigidbody2D rb; public float sila; public Animator anim; // Use this for initialization // Update is called once per frame void Update () { if (Input.GetKeyDown("d")) { rb.AddForce(Vector2.right * sila * Time.deltaTime,ForceMode2D.Force); Debug.Log("key pressed"); } if (Input.GetKeyUp("d")) { rb.velocity = new Vector2Int(0, 0); Debug.Log("key released"); } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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