/// <summary> /// Start the special mvoe /// </summary> override public void DoSpecialMove() { if (state == CeilingHangState.NONE) { state = CeilingHangState.HANG; character.SetVelocityX(0); character.SetVelocityY(0); character.Translate(0, yOffset, true); for (int i = 0; i < character.Colliders.Length; i++) { if (character.Colliders[i].RaycastType == RaycastType.HEAD) { RaycastHit2D hit = character.GetClosestCollision(i); if (hit.collider != null) { Platform tmpPlatform = hit.collider.GetComponent <Platform>(); if (tmpPlatform != null && !tmpPlatform.IgnoreCollision(character, character.Colliders[i])) { PlatformCollisionArgs platformCollisionArgs = new PlatformCollisionArgs(); platformCollisionArgs.Character = character; platformCollisionArgs.RaycastCollider = character.Colliders[i]; platformCollisionArgs.Penetration = 0; bool parent = tmpPlatform.Collide(platformCollisionArgs); if (parent) { character.ParentPlatform = tmpPlatform; character.ParentRaycastType = RaycastType.HEAD; } } } } } } }
/// <summary> /// Called when one of the characters colliders collides with this platform. This should be overriden for platform specific behaviour. /// </summary> /// <param name="PlatformCollisionArgs">Arguments describing a platform collision.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.HEAD && args.Character is Character) { DoHeadbutt((Character)args.Character); } return(false); }
/// <summary> /// Called when one of the characters colliders collides with this platform. This should be overriden for platform specific behaviour. /// </summary> /// <param name="PlatformCollisionArgs">Arguments describing a platform collision.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.FOOT && args.Character is Character) { CheckForEnter((Character)args.Character); } return(false); }
/// <summary> /// Called when one of the characters colliders collides with this platform. This handles basic shared behaviour. If you want to ignore it /// you can ovverride Collide() instead of CustomCollide(). /// </summary> /// <param name="PlatformCollisionArgs">Arguments describing a platform collision.</param> protected void BaseCollide(PlatformCollisionArgs args) { // Set friction if a foot is on this platform if (args.RaycastCollider.RaycastType == RaycastType.FOOT) { args.Character.Friction = Friction; } }
/// <summary> /// If the collission is a foot try to parent. /// </summary> /// <param name="character">Character.</param> /// <param name="type">Type of raycast.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.FOOT) { return(true); } return(false); }
/// <summary> /// If the collission is a foot try to parent. /// </summary> /// <param name="character">Character.</param> /// <param name="type">Type of raycast.</param> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.FOOT) { Debug.Log("Collide"); DoMove(args.Character); return(true); } return(false); }
/// <summary> /// If the collission is a foot try to parent. /// </summary> /// <param name="character">Character.</param> /// <param name="type">Type of raycast.</param> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.FOOT) { return(true); } if (parentOnHeadCollission && args.RaycastCollider.RaycastType == RaycastType.HEAD) { return(true); } return(false); }
/// <summary> /// Custom collission switch depth based on movement direction. /// </summary> /// <param name="PlatformCollisionArgs">Arguments describing a platform collision.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> /// <param name="args">Arguments.</param> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.FOOT) { if (args.Character.Velocity.x > 0) { args.Character.ZLayer = movingRightLayer; } if (args.Character.Velocity.x < 0) { args.Character.ZLayer = movingLeftLayer; } } return(false); }
/// <summary> /// Called when one of the characters colliders collides with this enemys head. /// </summary> /// <param name="PlatformCollisionArgs">Arguments describing a platform collision.</param> /// <returns>Always returns false.</returns> override public bool Collide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.FOOT) { // Apply upwards movement, this will work for most air movements, but in some cases you may need to provide a movement override args.Character.SetVelocityY(characterBobble); damageInfo.DamageCauser = args.Character; Debug.Log(damageInfo.DamageCauser); enemy.Damage(damageInfo); if (enemy.health <= 0) { // If the character is dead, turn everything off GetComponent <Collider2D>().enabled = false; enabled = false; } } return(false); }
/// <summary> /// If the collision is a foot and character is moving down get ready to launch. /// </summary> /// <param name="character">Character.</param> /// <param name="type">Type of raycast.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.Character is Character && (args.RaycastCollider.RaycastType == RaycastType.SIDE_RIGHT && springVelocity < 0) || (args.RaycastCollider.RaycastType == RaycastType.SIDE_LEFT && springVelocity > 0)) { if (character == args.Character) { return(true); } if (character == null) { character = (Character)args.Character; StopCoroutine(DelaySpring()); StartCoroutine(DelaySpring()); return(true); } } return(false); }
/// <summary> /// If the collision is a foot and character is moving down get ready to launch. /// </summary> /// <param name="character">Character.</param> /// <param name="type">Type of raycast.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.FOOT && args.Character is Character) { if (character == args.Character) { return(true); } if (args.Character.Velocity.y <= 0.0f) { if (character == null) { character = (Character)args.Character; StopCoroutine(DelaySpring()); StartCoroutine(DelaySpring()); return(true); } } } return(false); }
/// <summary> /// Initialise this instance. Called by the cahracter on start. /// </summary> /// <param name="character">Character.</param> virtual public void Init(Character character) { this.character = character; if (assumeConstantGravityAndFeetDistance) { for (int i = 0; i < character.Colliders.Length; i++) { if (character.Colliders[i].RaycastType == RaycastType.FOOT) { if (character.Gravity < 0) { timeToFallFeetDistance = Mathf.Sqrt((-2 * character.Colliders[i].Length) / character.Gravity); break; } } } } closestColliders = new int[character.Colliders.Length]; platformCollisionArgs = new PlatformCollisionArgs(); collidersAlreadySentMessages = new Collider2D[character.Colliders.Length]; }
/// <summary> /// Respond to colllisions /// </summary> /// <param name="character">Character.</param> /// <param name="type">Type of raycast.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> override protected bool CustomCollide(PlatformCollisionArgs args) { if (args.RaycastCollider.RaycastType == RaycastType.FOOT && args.Character.Velocity.y <= 0.0f && args.Character is Character) { if (!isBeingStoodOn && triggeEnterOnStand) { myTrigger.CharacterEnteredTrigger((Character)args.Character); } isBeingStoodOn = true; feetCount++; lastCharacterToStand = (Character)args.Character; } if (args.RaycastCollider.RaycastType == RaycastType.HEAD && args.Character.Velocity.y > 0.0f && args.Character is Character) { if (headCount == 0 && triggedOnHeadButt) { myTrigger.CharacterEnteredTrigger((Character)args.Character); } headCount++; } return(false); }
/// <summary> /// Called when one of the characters colliders collides with this platform. This should be overriden for platform specific behaviour. /// </summary> /// <param name="PlatformCollisionArgs">Arguments describing a platform collision.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> virtual protected bool CustomCollide(PlatformCollisionArgs args) { return(false); }
/// <summary> /// Called when one of the characters colliders collides with this platform. /// </summary> /// <param name="PlatformCollisionArgs">Arguments describing a platform collision.</param> /// <returns>true if character should be parented to this platform, otherwise false.</returns> virtual public bool Collide(PlatformCollisionArgs args) { BaseCollide(args); return(CustomCollide(args)); }
/// <summary> /// Called when one of the characters colliders collides with this platform. /// </summary> /// <param name="character">Character.</param> /// <param name="type">Type of raycast.</param> /// <returns>tAlways returns false.</returns> override public bool Collide(PlatformCollisionArgs args) { Debug.Log("Collide: " + args.Character + " " + args.RaycastCollider.RaycastType); return(false); }