- Home /
This question was
closed May 19, 2013 at 09:52 PM by
KMKxJOEY1 for the following reason:
The question is answered, right answer was accepted
What's wrong with my sprinting logic?
it seems like my 'down' boolean isn't updating, any help plz?
Here is my code:
public void sprintManager()
{
if(needsSprint)
{
if(down)
{
CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintLoopAnim].speed = 0.5f;
CurrentWeapon.WeaponTransform.animation.CrossFade(CurrentWeapon.sprintLoopAnim,0.2f);
}
else
down_to_sprint();
}
else
{
up_from_sprint();
}
}
void down_to_sprint()
{
CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintInAnim].speed = 0.5f;
CurrentWeapon.WeaponTransform.animation.CrossFade(CurrentWeapon.sprintInAnim,0.2f);
if(animation_finished(CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintInAnim].name))
down = true;
}
void up_from_sprint()
{
if(down)
{
CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintOutAnim].speed = 0.5f;
CurrentWeapon.WeaponTransform.animation.CrossFade(CurrentWeapon.sprintOutAnim,0.2f);
if(animation_finished(CurrentWeapon.WeaponTransform.animation[CurrentWeapon.sprintOutAnim].name))
{
down = false;
force_idle();
}
}
}
public bool animation_finished(string anim)
{
if(CurrentWeapon.WeaponTransform.animation.IsPlaying(anim) || CurrentWeapon.WeaponTransform.animation[anim].normalizedTime >= 1 )
return true;
else
return false;
}
Comment
Could you post something about how needSprint is toggled and how these booleans are initialized? NeedSprint =true if something is pressed? Down is default true or false?
down is default false and needSprint is toggled by the player speed, but here is the code if you would like to take a look:
//walking
if(walkingstate == WalkingState.Running)
{
needsSprint = true;
if(down)
down = false;
}
else if(walkingstate == WalkingState.Walking)
{
WalkAnimationHolder.animation["walking"].speed = Velocity$$anonymous$$agnitude / walkSpeed;
WalkAnimationHolder.animation.CrossFade("walking", 0.2f);
WalkAnimationHolder.transform.rotation = WalkAnimationHolder.transform.parent.rotation;
needsSprint = false;
}
else
{
needsSprint = false;
if(!isAi$$anonymous$$g)
{
WalkAnimationHolder.animation.CrossFade("spreader_idle", 0.2f);
WalkAnimationHolder.transform.rotation = WalkAnimationHolder.transform.parent.rotation;
}
else
{
WalkAnimationHolder.animation.Rewind();
ADSHolder.localPosition = Vector3.Lerp(ADSHolder.localPosition, CurrentWeapon.Scopes[CurrentWeapon.CurrentScope].ADSPos, 1f);
}
}
Follow this Question
Related Questions
How to disable sprinting when slider reaches zero. 1 Answer
Can someone help me add running to my script? 1 Answer
Sprinting Script Issue 1 Answer
Character Jumping while Sprinting Code? 1 Answer
Mid air "sprint" 2 Answers