|
This should be straightforward, or so I thought. Getting quite late so probably just tiredness dumbing me down. I could use a fresh set of eyes on this. In our game the player character needs to be able to move at different speeds depending on the keys held down. By default, the PC will move at the walkSpeed, and with "c" held down will slow to a crawl, while with "left shift" held down will accelerate to his top sprinting speed. I'd also like to include stamina, so that after a few seconds at top speed, the PC slows back to walking speed and must wait for a cool down period before being able to sprint again. Here's my script so far. It's a modified version of the FPSWalker script For some reason, holding shift only increases the speed by 1, and not continuously until the limit as i'd like, despite using Input.GetButton to do it as long as the key is held down. Changing speeds worked with hardcoded values, but we'd like to have speeds in multiples like this so it's easier to scale. Also the sprint stamina timer doesn't seem to be having an effect.
(comments are locked)
|
|
The problem with the above code is that you're setting currentSpeed at the top of Update, so each time you increase it, next time it's walk speed again I would set it to that only if crouch and run is not held - also, you should probably set the crouch speed to walkSpeed *0.5 instead of currentSpeed *0.5, otherwise you may get odd speeds when runcrouching Hi Mike, thanks for that. I knew it would be something obvious - i've actually just now been implementing something else and had to add an if statement to stop overriding the speed in Update() so I should've realised. It seems to be working now except it never seems to reach the maxSpeed of 15, it gets to 13. Any reason why that would be? I've amended my code above with your suggestions.
May 19 '10 at 03:15 AM
straydogstrut
Can't really see any bugs there straight off - i would check that the values are set right in the inspector (i.e. it's set to 15, not 13 there) and check it's not hitting the cooldown
May 19 '10 at 07:15 PM
Mike 3
(comments are locked)
|
