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

Moving an object and returning to location based on collider

$
0
0
I am trying to take an object and move it when my character gets close to it, but return it to its original position when I move away. I re-purposed a script I found for making an object rotate when you got close (like a door). In my edited version, I am able to get the object to move, but it won't stop moving and won't return to its position when I move away from it. Any advice? Using Javascript... var ObjMoveValue : float = 1.0; private var targetValue : float = 0.0; private var currentValue : float = 0.0; private var easing : float = 0.02; var ObjToMove : GameObject; function Update(){ currentValue = currentValue + (targetValue - currentValue) * easing; ObjToMove.transform.Translate(0, currentValue * Time.deltaTime, 0); } function OnTriggerEnter (other : Collider) { targetValue = ObjMoveValue; currentValue = 0.0; } function OnTriggerExit (other : Collider) { // currentValue = ObjMoveValue; targetValue = 0.0; }

Viewing all articles
Browse latest Browse all 1875

Trending Articles



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