- Home /
Question by
maxima06 · Mar 17, 2020 at 04:42 PM ·
positionmovement scriptmove an object
[SOLVED] Gameobject is vibrating throughout the movement.
Hello to everyone, I have a GameObject that takes position coordinates from a file. This GameObject moves vibrating rather than smoothly.
It is the code that the movement is provided:
int counter = 0;
var maxDistance = 300f * Time.deltaTime;
var oldPosition = transform.position;
var newPosition = Vector3.MoveTowards(transform.position, positions[counter], maxDistance);
var actualDistance = Vector3.Distance(newPosition, oldPosition);
var distanceRemainder = maxDistance - actualDistance;
if (distanceRemainder > 0.0001)
{
newPosition = Vector3.MoveTowards(newPosition, positions[counter], distanceRemainder);
counter++;
}
transform.localPosition = newPosition;
NOTE: The "positions" array in this code is the array with the x, y, z coordinates.
When I lower the 300f value in the variable maxDistance, the vibration stops and the motion becomes more fluid. However, Gameobject speed is also slowing down. How can I ensure a fast and smooth movement?
SOLVED
The solution for the problem can be found at this link.
Comment
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
transform.position not moving object 2 Answers
Helicoper Movement Help 1 Answer
How to drag a game object with a mouse (along x axis)? 1 Answer