Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Objects not moving smoothly with Vector3.Lerp

$
0
0
So I'm trying to make a drawer of sorts that will pull a couple of prefabs from out of the frame. However I've been trying to get them to smoothly move from out of frame into frame and I can't seem to get it right. I've been fiddling with the Vector.Lerp() but it doesn't seem to work like I thought it would. After detecting if the "drawer handle" has been clicked I have the objects set to move with : var smoothTime = 2; var atomSpawner : GameObject; var startPos : Vector3; var endPos : Vector3; function Update(){ if(drawerOpen == true){ if(hit.collider.tag == "slider"){ atomSpawner.transform.position = Vector3.Lerp(atomSpawner.transform.position, startPos, Time.deltaTime * smoothTime); drawerOpen = false; } } else{ if(hit.collider.tag == "slider"){ atomSpawner.transform.position = Vector3.Lerp(atomSpawner.transform.position, endPos, Time.deltaTime * smoothTime); drawerOpen = true; } } } I've tried messing around with the smoothTime number and that doesn't seem to affect it all that much, I've also tried swapping out atomSpawner.transform.position with either endPos and startPos, which just cause it to go from endPos to startPos / startPos to endPos immedietly.

Viewing all articles
Browse latest Browse all 1875

Trending Articles



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