- Home /
Lift issues in Unity
Hey all! I have a script that is mostly working to cause a "lift" to raise or lower when holding down an "action key" (I use the "e" key). My problem is that is seams to be moving the lift based off the current time in the game. If I hold down the "e" key, it transitions smoothly from pointA to pointB, and stops moving when I release the "e" key. However, if I press the "e" key again the lift will jump in the direction it was moving, and the longer i wait to click it again, the farther it jumps. If anyone knows how to fix this it would be very helpfull! Thanks!
var speed : float = 0.01; var activationKey:String="e"; var playerThere:boolean=false; var targetA:GameObject; var targetB:GameObject;
function Update (){ if(playerThere){ if(Input.GetKey(activationKey)){ var weight = Mathf.Sin(Time.time speed .1 Mathf.PI) 1 + 1; transform.position = targetA.transform.position weight + targetB.transform.position (1-weight); } } }
function OnTriggerEnter(hit){ if(hit.tag=="Player"){ playerThere=true; print("player is here"); } } function OnTriggerExit(hit){ if(hit.tag=="Player"){ playerThere=false; print("player is not here"); } }
Answer by azzogat · Dec 12, 2010 at 12:16 PM
Translating objects framerate-independently is done by using Time.deltaTime not Time.time.
Time.time just outputs the time passed since the start of the game.
Hey Azzogat! Thanks for helping me here. I have tried Time.deltaTime, and when I use it, the lift just goes to point B instantly, and no longer goes back to point A. It should work, and I don't understand how just changing how the script work with time since the game started and frame rate can break it like that. Thanks again for the info though!
Your answer
Follow this Question
Related Questions
Transform localPosition on time 2 Answers
2d Platformer Jumping Not Working 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
Does anyone know what i am doing wrong? 0 Answers