- Home /
Stutter problem, no physics
Can't deal with a stutter issue. Moving object in Update, using Time.deltaTime. No physics.
Object moves from point to point.
Without rotation it moves smooth, but when I add rotation logic I can see the motion stutter. I've tried different ways to solve this - tied FixedUpdate, smoothDeltaTime etc etc - nothing helped (
Maybe some one can give an advice - I am totally frustrated and can't continue developing my game.
public void Update() {
var nextStep = GetNextStepData(currentGoalPoint, transform.position,
(transform.rotation.eulerAngles.z + 90) * Mathf.Deg2Rad);
CurrentSpeed = nextStep.Speed;
transform.position = nextStep.Position;
transform.rotation = Quaternion.AngleAxis(nextStep.Rotation * Mathf.Rad2Deg - 90, Vector3.forward);
}
protected NextStepData GetNextStepData(GameObject goalPoint, Vector3 currentPointPosition,
float currentPointRotationRadians)
{
var timeCoeff = Time.deltaTime * 15f;
var deltaY = goalPoint.transform.localPosition.y - currentPointPosition.y;
var deltaX = goalPoint.transform.localPosition.x - currentPointPosition.x;
var goalRotation = Math.Atan2(deltaY, deltaX);
var rotationDelta = goalRotation - currentPointRotationRadians;
while (rotationDelta > Math.PI)
{
rotationDelta -= Math.PI * 2;
}
while (rotationDelta < -Math.PI)
{
rotationDelta += Math.PI * 2;
}
currentPointRotationRadians = (float) (currentPointRotationRadians + rotationDelta * TurnCoeff * timeCoeff);
var dirX = (float) Math.Cos(currentPointRotationRadians);
var dirY = (float) Math.Sin(currentPointRotationRadians);
return new NextStepData
{
Position =
new Vector3(currentPointPosition.x + dirX*timeCoeff, currentPointPosition.y + dirY * timeCoeff,
currentPointPosition.z),
Rotation = currentPointRotationRadians,
};
}
Comment
Your answer
Follow this Question
Related Questions
Add 1 Per Second to an Int 1 Answer
Time.deltaTime not consistent over time 1 Answer
Movement using Time.deltaTime not working on Fast mac 3 Answers
Execute code every x seconds with Update() 4 Answers
Lerp stopping/not working? 1 Answer