Quantcast
Channel: Questions in topic: "count"
Viewing all articles
Browse latest Browse all 187

Calculate UP Distance Displacement for 3D Infinity Runner Game

$
0
0
Hi guys, I'm a little noob with programming and need some help with an issue. I'm doing an infinity runner 3D space shooter where my character only moves on the Y Up axis and can rotate his spaceship 360 degrees to move left and right like a rocket. I made a distance script counter where it shows the distance that the player traveled flying upwards when he press the fly button, but **I need some help with only counts the distance if he is "going up"** , because the script still counts the distance even if the ship is flying down or is flying sideways. So the question is: how to write for the distance counter script only counts meters if the spaceship is flying up? Here is my script public class distanceCounter : MonoBehaviour { Text mtTxt; [SerializeField] private float distance; [SerializeField] private GameObject player; [SerializeField] private float curPos; void Start () { mtTxt = GetComponent (); curPos = player.transform.position.y; } void Update () { if (TouchControls.startMeters == true) { distance += Time.deltaTime * curPos; } mtTxt.text = "Meters: " + distance + " m"; } }

Viewing all articles
Browse latest Browse all 187

Trending Articles



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