Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Acceleration and Delta Time

$
0
0
Hello everyone! I have a script called MovementMotor which control's character movement. I've multiplied the final speed by Time.deltaTime so movement speed is framerate independent. However, the amount of time that it takes for the character to reach maximum speed is not affected. How can I fix this so acceleration changes based on delta time? Here is the code inside Update(): *direction* and *angularDirection* tell whether the keys are down or not. if (direction.x == 0) { velocity.x *= friction; } else { velocity.x += direction.x * accelaration; } if (direction.y == 0) { velocity.y *= friction; } else { velocity.y += direction.y * accelaration; } if (angularDirection == 0) { angularVelocity *= angularFriction; } else { angularVelocity += angularDirection * angularAccelaration; } if (velocity.sqrMagnitude > 1f) { velocity.Normalize(); } if (angularVelocity > 1f) { angularVelocity = 1f; } else if (angularVelocity < -1f) { angularVelocity = -1f; } transform.Rotate(new Vector3(0, 0, angularVelocity * angularSpeed * Time.deltaTime)); transform.Translate(velocity.x * speed * Time.deltaTime, velocity.y * speed * Time.deltaTime, 0); direction = new Vector3(0, 0, 0); angularDirection = 0; Thanks a lot :) Any help is appreciated!

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>