Quantcast
Channel: Answers by "Duckocide"
Viewing all articles
Browse latest Browse all 25

Answer by Duckocide

$
0
0
Hi @JesperGreen There are a few tricks to this, but looking at your code, you perhaps need to consider the "distPos" value and make it Clamp01(...) (Keeps it between 0 and 1) and use the key press to flip the direction. Something like (I've just typed this in here, not tested / syntax checked)... Extra declarations... float direction = 1f; // The direction of travel float maxDistance = 2f; // The maximum move distance Start() { StartPos = transform.position; EndPos = StartPos + Vector3.forward * maxDistance; } Update() { if (Input.GetKey(KeyCode.UpArrow)) direction = 1f; else direction = -1f; distPos = Mathf.Clamp01(distPos + (time.deltaTime * moveSpeed * direction)); transform.position = Vector3.Lerp(StartPos, EndPos, distPos); } Hope this helps :)

Viewing all articles
Browse latest Browse all 25

Trending Articles



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