I am working on an fps game that uses sliding and crouching, but, currently, my character slides infinitely without stopping (until I release the shift key). If somebody can help me, that would be greatly appreciated! Thank you in advance!
Asked
Active
Viewed 471 times
-3
-
What code do you have at the moment? It sounds like you are most of the way there. When you press shift it just needs to start the slide, which then continues for a set period of time/distance in that direction before control is returned to the player. The way I like to handle this in player controllers is to have a simple state machine (using an enum of states and a switch case statement to execute the right code depending on what state the player is in). – TheLastBert Jul 30 '21 at 15:48
1 Answers
0
The easiest would be to implement a timer that automatically cancels sliding. Something like this:
public float timeRemaining;
void Update(){
timeRemaining =- time.deltaTime;
if(timeRemaining < 0f){
//StopSliding
}
}
Of coarse you would have to set timeRemaining in your function for Sliding.

99thGamer
- 3
- 3