Hello wick comunity, could someone please tell me how to make a sprint system, it’s for an school project I have that involves a game.
What you can do is this
Put this in default tab for the play:
this.speed = 10 (You can always change this number)
this.sprint = 1 (Don’t change this number)
Now put this in the update tab for the player
If(isKeyDown(‘right’)){
this.x+=this.speed * this.sprint
)
If(isKeyDown(‘left’)){
this.x-=this.speed * this.sprint
)
To enable sprint (put this in update tab for player)
if(isKeyDown(‘space’)){
this.sprint = 2 (you can always change this number)
}else{
this.sprint = 1 (Don’t change this number)
}
And that it, I hoped this is what you mean by sprint system
Well I have the sprint tingy done, I just have to know how to make an stamina bar that works with the sprinting system.
Oh, you want to have a stamina bar
Ok so go to player and type this in the default tab
this.stamina=300 ( tho you can change this, how long you want the player stamina to be)
then go to update tab for the player and type
//this is to gain stamina when user is not using the sprint key
if(isKeyDown(‘space’) === false){
this.stamina+=1
}
//this here to make sure stamina doesnt go over the limit
if(this.stamina>300){
this.stamina=300
}
and this is if player uses the sprint key it changes the player speed while also using stamina
if(this.stamina>0){
if(isKeyDown(‘space’)){
this.sprint=2
this.stamina-=1
}
}
and that should work of course you can change the key for sprint and the max for sprint.
I hope this help