- Home /
Why is Spaceship vibrating as it moves ?
I'm trying to move ship but it's not moving smoothly. The ship is vibrating as it moves.
void MoveShip()
{
float yPos = Input.GetAxis("Vertical") * Time.deltaTime * movementSpeed + transform.position.y;
float zPos = Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed + transform.position.z;
transform.position = new Vector3(transform.position.x, yPos, zPos);
if (movementSpeed <= 15)
{
movementSpeed = 15;
}
}
This video may help understanding https://streamable.com/6vrymw
Answer by Grybacijus · Mar 02, 2021 at 06:14 PM
Are you moving the ship in update method? If so try moving it to fixed update.
It worked. Really thanks ! But can you explain why did it work ? What is the logic behind it ? And Should I always use FixedUpdate instead update ?
Fixed Update happens in fixed intervals while Update happens once per frame. Framerate can vary and cause unexpected results and is often the cause of skipping in movement.
In short: FixedUpdate() is called at even periods, while Update() depends on frame-rate.
Update()
- Called every frame
Used for regular updates such as :
Moving non-physics objects
Simple timers
Receiving input (aka keypress etc)
Update interval call times will vary, ie non-uniformly spaced
FixedUpdate()
- Called every physics step - FixedUpdate() intervals are consistent, ie uniformly spaced - Used for regular updates such as adjusting physic (eg. RigidBody) objects
Answer taken from this stack overflow question answer by jfunk
Your answer
Follow this Question
Related Questions
Why is transform.position is not so acurate? 1 Answer
Transform Position doesn't work 0 Answers
geting GameObject transform position gives Spasmic numbers 1 Answer
Character controller problem 2 Answers