Constantly change speed of player based on the given distances
Hi,
My game designer sends me a request like this attachment. He wants to constantly change the speed of the character based only the distances the player reaches. Ex: Increase constantly from 0 to 10 m/s in first 100 m. Then increase from 10 to 20 from 100-500m. Since this is infinite running game, there will be no limitation for the distance. Any one have the idea to achieve this?
Besides, there will be the Speed Up item. So how to apply it, for example if player takes it at 990 m?
Thanks.
$$anonymous$$ove the "world" ins$$anonymous$$d of the player and keep track of how much you have moved it.
Answer by Brylos · Dec 12, 2016 at 05:00 PM
I'm assuming you have the controller functioning and have the ability to change speed values. Assuming that, you can have your speed increase by using Time.deltatime multiplied by a float.
float PlayerSpeed;
float Acceleration;
Start()
{
PlayerSpeed += Time.deltatime * Acceleration;
}
You'll have to mess around with the math to get it matched to that graph but that is basically how you would do it.
Speed isn't directly affected by the distance in this example, however this would work if the player doesn't have the option to stop in place.
Answer by Konomira · Dec 12, 2016 at 05:06 PM
Something along the lines of this would work. Obviously you add your own movement script and just use the float 'movespeed' to define your speed.
float moveSpeed = 0f,
speedIncreaseRate = 0.05f;
Vector3 startPosition;
void Start()
{
startPosition = transform.position;
}
void Update()
{
moveSpeed = Vector3.Distance(transform.position, startPosition) * speedIncreaseRate;
//Move Script
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612102551im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to revert speed back to normal after changing with Key. 1 Answer
Something is wrong with my max. speed code 0 Answers
Increase variable? 0 Answers
Can a csv file be used to change a player speed? 0 Answers
Virtual Joystick Player Speed Problem 0 Answers