- Home /
Quality settings, alter player speed/input
I'm creating a simple platformer, and I'm moving my character by applying force
if (Input.GetKey ("right")) {
rigidbody.AddForce (Vector3.forward * 10); }
When testing with player settings, and quality it turns out that the player on fastest, and below beautiful settings will zoom about the screen, and not at the set pace.
Any suggestions on how I can limit the speed, or would it be best to just set all Quality Setting in the Inspector to the same?
Answer by rutter · Jul 06, 2012 at 11:42 PM
In simple use cases, someone moves their character 10 units per frame:
void Update()
{
transform.position += Vector3.forward * 10f;
}
We tell them to adjust this value by the frame time, moving by 10 units per second instead of per frame:
void Update()
{
transform.position += Vector3.forward * 10f * Time.deltaTime;
}
If you're not adding force with some fixed number of times per second, you'll have a similar issue: the faster the game runs, the more often your update loop will fire, the more force you'll be adding. If you're not careful, that can come back to bite you.
If you're willing to spend some time implementing actual kinematics for your character's movement (acceleration, velocity, and so on), that should solve your problem. If you're looking for more of a quick fix, multiplying your force by frame time will help but probably won't completely fix the problem.
Bear in mind that Time.deltaTime
is usually a very small value, around 0.02 to 0.05 depending on your performance, and that you'll probably want to increase your other constants once you add the coefficient.
Thank you for this, I had just last night implemented
"transform.position += Vector3.forward 10f Time.deltaTime;"
And it's brilliant. I think I will take some time out to implement some kinematics. It's essential the player is fluent.
Your answer
Follow this Question
Related Questions
Game running at different speeds on different quality levels. 1 Answer
2D 360 degress platformer example needed 0 Answers
More Realistic Physics 1 Answer
Breaking joints 1 Answer
bow and arrow game 6 Answers