// Update is called once per frame void Update() { float width = (float)health / (float)400; healthbar.rectTransform.sizeDelta = new Vector2(width * 600, 40); switch (state) { case LegStates.following: Vector3 direction = (player.transform.position - transform.position).normalized; direction.y = 0; gameObject.transform.position += direction * speed * Time.deltaTime; gameObject.transform.LookAt(transform.position + direction); animator.SetBool("Walking", true); if ((player.transform.position - transform.position).magnitude <= 5) { state = LegStates.kicking; animator.SetBool("Walking", false); animator.SetBool("Kicking", true); kicking = true; } break; case LegStates.kicking: cooldownTimer -= Time.deltaTime; if (cooldownTimer <= 0) { playerkicked = false; kicking = false; animator.SetBool("Kicking", false); state = LegStates.cooldown; cooldownTimer = 5; } break; case LegStates.cooldown: cooldownTimer -= Time.deltaTime; if (cooldownTimer <= 0) { state = LegStates.following; cooldownTimer = 1; } break; } }
public void Update(float dtime, InputHelper input) { HandleInput(input); Tangent.X = (float)Math.Cos(BodyTorso.Rotation); Tangent.Y = (float)Math.Sin(BodyTorso.Rotation); Normal.X = -Tangent.Y; Normal.Y = Tangent.X; if (LegState == LegStates.Leaping && BodyTorso.LinearVelocity.Y > 0 && IsLandable) { LegState = LegStates.Squatting; } if (LegState != LegStateOld) { switch (LegState) { case LegStates.Standing: SpriteLeg.Texture = TextureStanding; break; case LegStates.Squatting: SpriteLeg.Texture = TextureSquatting; break; case LegStates.Leaping: SpriteLeg.Texture = TextureLeaping; break; case LegStates.Walking1: SpriteLeg.Texture = TextureWalking1; break; case LegStates.Walking2: SpriteLeg.Texture = TextureWalking2; break; case LegStates.Walking3: SpriteLeg.Texture = TextureWalking3; break; default: break; } } LegStateOld = LegState; }
public void Hop() { LegState = LegStates.Leaping; BodyTorso.ApplyForce(Normal * HopForce * -1); IsLandable = false; timerLandable.Start(); }
public void Stand() { LegState = LegStates.Standing; physicsSimulator.Add(GeomLegsStanding); }
public void Squat() { LegState = LegStates.Squatting; BodyTorso.ApplyForce(Normal * JumpForce); physicsSimulator.Remove(GeomLegsStanding); }
private bool OnCollision(Geom geom1, Geom geom2, ContactList contactList) { bool result = true; IsGrounded = true; if (geom1 == GeomLegsStanding && IsLandable && !IsWalking) { LegState = LegStates.Standing; } return result; }
void timerWalking_Elapsed(object sender, ElapsedEventArgs e) { if (IsGrounded) { if (LegState == LegStates.Walking1) LegState = LegStates.Walking2; else if (LegState == LegStates.Walking2) LegState = LegStates.Walking3; else if (LegState == LegStates.Walking3) LegState = LegStates.Walking1; else LegState = LegStates.Walking1; } }