- Home /
A bit shaky when translating
I noticed a problem in Unity with translate. When use getAxis for translation. It moves smoothly but the object was a bit shaky while moving. My code is very simple
void Update () {
float hori = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
Vector2 transVector = new Vector2(hori, ver);
transform.Translate(transVector * 5 * Time.deltaTime);
}
Here is an example of my problem:
https://docs.google.com/file/d/0B7nGTxuhFgJQZlZ3WHprRWFmc1k/edit?usp=sharing
There is a cube and an animated skeleton. The effect might not be obvious with cube but is very obvious with the skeleton. Even it moves at smooth rate but it's shaky and is unbearable.
I have tried this on several computers and they all have the same problem. I've never been able to get a completely smooth without shaking movement in unity. Can someone help? Thanks
Are you certain it's the transform and not your mouse? Have you tried using a different source of input perhaps, or a better mouse pad/better mouse? I really don't see any reason why this would be happening, given what you've used, here, aside from that or the distinct possibility that you might have too much other stuff going on that's bogging down the system, and the shaking may be caused by a slight lag?
Normally, I'd say you should be using FixedUpdate for a transform alteration, but given that you're using an input for it, you want it called each frame, so that's not really an option :P
I haven't seen a Vector2 parameter for Translate before
@DESTRU$$anonymous$$TORR I'm using keyboard actually, four arrow keys. I have very little stuff in the program and I have a very powerful computer so I don't think it's the performance issue. Please take a look at the link I provide, run the .exe and you will see what I mean.
Answer by TheValar · Oct 21, 2013 at 06:36 PM
This may be a long shot but try using
transform.position = Vector3.Lerp(startPos, endPos, t); instead of transform.Translate(transVector 5 Time.deltaTime);
obviously you will need to set startPos, endPos, and t appropriatly. Someone suggested this in another post that I read recently.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113318im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Smoothing out translation for movement? 0 Answers
Smooth movement using Rigidbody2d 3 Answers
Smooth Camera Movement script with problem. 0 Answers
Move along grid where facing 1 Answer
Object transported to point instead of moving towards it? 1 Answer