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

why does my addforce only last for a split second?

$
0
0
im very new to coding so sry if this is a simple mistake. ive set up my cube to move in any direction but for some reason whenever i press a button to move i move in the direction i pressed but only for a split second even if i hold the key down. here is my script using System.Collections; using System.Collections.Generic; using UnityEngine; public class ri : MonoBehaviour { private Rigidbody rb; public int speed; public int hspeed; // Start is called before the first frame update void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { if (Input.GetKeyDown("w")) { rb.AddForce(transform.forward * 100); } if (Input.GetKeyDown("s")) { rb.AddForce(0, 0, -speed); } if (Input.GetKeyDown("a")) { rb.AddForce(hspeed, 0, 0); } if (Input.GetKeyDown("d")) { rb.AddForce(-hspeed, 0, 0); } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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