public void OnAfterMove(Character ch, float delta) { if (ch.IsOnState(States.Pulling)) { PullBox( ch.movedLastFrame, // do not use velocity ch.faceDir == Facing.Right ? Directions.Left : Directions.Right, delta ); } }
public void OnBeforeMove(Character ch, float delta) { if (ch.IsOnState(States.Pushing)) { if (ch.faceDir == Facing.Right) { PushBox(ch.velocity * delta, ref ch.pc2d.collisions.rightHits, ch.pc2d.collisions.rightHitsIdx, delta); } else { PushBox(ch.velocity * delta, ref ch.pc2d.collisions.leftHits, ch.pc2d.collisions.leftHitsIdx, delta); } } }
public void OnBeforeMove(Character ch, float delta) { // TODO test if give better results // disable all boxes // move character // enable all boxes // after move it use movedLastFrame as velocity // NOTE should not kill the character! if (ch.IsOnState(States.Pushing)) { PushBox( ch.velocity * delta, ch.faceDir == Facing.Right ? Directions.Right : Directions.Left, delta ); } }
/// <summary> /// Calculate what animation to play and do it! /// </summary> public virtual void PlatformerUpdate(float delta) { if (character.faceDir == Facing.Right) { transform.localScale = new Vector3(1, 1, 1); } else { transform.localScale = new Vector3(-1, 1, 1); } if (rotateOnSlopes) { if ( character.collisions.slopeAngle != 0 && character.collisions.below && !character.collisions.left && !character.collisions.right && maxSlope > character.collisions.slopeAngle ) { float angle = 90 - Mathf.Atan2(character.collisions.slopeNormal.y, -character.collisions.slopeNormal.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); } else { transform.rotation = Quaternion.identity; } } if (character.forceAnimation != null) { Play(character.forceAnimation); } else if (character.IsOnState(States.Rope)) { Play(rope); // override rotation float z = character.rope.sections[character.ropeIndex].transform.eulerAngles.z; transform.rotation = Quaternion.AngleAxis(z, Vector3.forward); } else if (character.IsOnState(States.Pushing)) { Play(pushing); } else if (character.IsOnState(States.Pulling)) { Play(pulling); } else if (character.IsOnState(States.Liquid)) { Play(swimming); } else if (character.IsOnState(States.WallSliding)) { Play(wallsliding); } else if (character.IsOnState(States.Slipping)) { Play(slipping); } else if (character.IsOnState(States.Grabbing)) { Play(grabbing); } else if (character.IsOnState(States.MeleeAttack)) { Play(attackMelee); } else if (character.IsOnState(States.Ladder)) { Play(ladder); } else if (character.IsOnState(States.Fence)) { // left/right has priority if (character.velocity.x != 0) { Play(Mathf.Sign(character.velocity.x) == 1 ? fenceRight : fenceLeft); } else if (character.velocity.y != 0) { Play(Mathf.Sign(character.velocity.y) == 1 ? fenceUp : fenceDown); } else { Play(fenceIdle); } } else if (character.IsOnState(States.Jumping)) { //Transition("jump_start", 0.1f); Play(jump); } else if (character.IsOnState(States.Falling)) { Play(fallLoop); } else { if (character.IsOnState(States.Crounch)) { if (character.velocity.x != 0) { Play(crounchWalk); } else { Play(crounchIdle); } } else { if (character.velocity.x != 0) { Play(walk); } else { Play(idle); } } } }
public virtual void PlatformerUpdate(float delta) { if (character.faceDir == Facing.Right) { transform.localScale = new Vector3(1, 1, 1); } else { transform.localScale = new Vector3(-1, 1, 1); } if (rotateOnSlopes) { if ( character.pc2d.collisions.slopeAngle != 0 && character.pc2d.collisions.below && !character.pc2d.collisions.left && !character.pc2d.collisions.right && maxSlope > character.pc2d.collisions.slopeAngle ) { float angle = 90 - Mathf.Atan2(character.pc2d.collisions.slopeNormal.y, -character.pc2d.collisions.slopeNormal.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); } else { transform.rotation = Quaternion.identity; } } if (character.forceAnimation != null) { Play(character.forceAnimation); } else if (character.IsOnState(States.Rope)) { Play("rope"); // override rotation float z = character.rope.sections[character.ropeIndex].transform.eulerAngles.z; transform.rotation = Quaternion.AngleAxis(z, Vector3.forward); } else if (character.IsOnState(States.Pushing)) { Play("pushing"); } else if (character.IsOnState(States.Pulling)) { Play("pulling"); } else if (character.IsOnState(States.Liquid)) { Play("swimming"); } else if (character.IsOnState(States.WallSliding)) { Play("wallsliding"); } else if (character.IsOnState(States.Slipping)) { Play("slipping"); } else if (character.IsOnState(States.Grabbing)) { Play("grabbing"); } else if (character.IsOnState(States.MeleeAttack)) { Play("attack_melee"); } else if (character.IsOnState(States.Ladder)) { Play("ladder"); } else if (character.IsOnState(States.Jumping)) { //Transition("jump_start", 0.1f); Play("jump"); } else if (character.IsOnState(States.Falling)) { Play("falling"); } else { string modifier = ""; if (character.IsOnState(States.Crounch)) { modifier = "crounch_"; } if (character.velocity.x != 0) { Play(modifier + "walk"); } else { Play(modifier + "idle"); } } }