- Home /
fixed update predicament
hi everyone quick questin on fixed update, i asked this a while ago but have never got a direct answer. i want to know how to assign a key press to a physics movement properly.
so for instance when i press down on my keyboard my ball moves forward by torque and when i take my finger of it slows down.
now my question how to assign the key press and physics properly i read that input should be done in an update function. however i need my torque in a fixed update. what is the proper way of doing this. should i use a simple fixeddelta time inside the update or assign a new script. currently all my controls are in one control manager to optimise script updates.
im also developing for iphone so i really need to know the best way for performance please thanks....
posting a commment so i might be able to get an answer
Answer by aldonaletto · Apr 25, 2012 at 12:18 AM
The problem in reading Input outside Update is related to functions that report button transitions (like GetKeyDown/Up, GetButtonDown/Up etc.), because these transitions are valid during the whole Update cycle where the event occurred. You will not have problems with functions that report continuous states like GetAxis, GetKey, GetButton etc. - what seems to be your case.
im using multi touch on ios gui, however im not using on gui, im using hit test.phase in a touch loop in a fixed function.
so for one i will have
on touch add torque by 200
what i need to do is to split them up so the touch is in update and the other in fixed, if i applied the fixed delta time to the torque would that be like seperating into those catorgories..
oh i havent really noticed much loss in response to the gui unless i get lag which is because i have a lot of objects not combined yet and components not cached.
$$anonymous$$y bad! I haven't noticed you're developing for touch screen... Anyway, you could store your "button state" in some boolean variable and use it in FixedUpdate.
You don't have to worry about deltaTime when using AddTorque or AddForce in FixedUpdate - the torque/force is applied during the whole physics cycle, which always have the same duration (fixedDeltaTime) in the internal physics clock.
i did think of doing a simple on of function, i might try it. im also trying to $$anonymous$$imise functions used though as i heard they decrease performance. i try to only have one main update function running at any given time.
i thought maybe i could just chuck it all into an update with a fixed delta time for the torque
You may have a somewhat random result - from the physics engine point of view, Update occurs at very unpredictable and irregular rate, and this could cause the force/torque to be applied at random intervals if Update is slower than FixedUpdate.
On the other hand, movement is the integral of the integral of the force, what works like a filter and greatly smooths out the effects of force variations.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
C# UNITY_IPHONE, Still executing in update()? 1 Answer
Interpolated Fixed Timestep 2 Answers
Updating Unity 1 Answer
Failed to update unity web player. 1 Answer