Esempio n. 1
0
 /// <summary>
 /// Stand on a respawn point to activate it. You could play a particle effect of something here.
 /// </summary>
 override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     if (collider.direction == RC_Direction.DOWN)
     {
         currentRespawnPoint = this;
     }
 }
Esempio n. 2
0
	override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		// If we are standing on this
		if (!alreadyAdded && collider.direction == RC_Direction.DOWN) {
			character.Velocity += speed;
			alreadyAdded = true;
		}
	}
Esempio n. 3
0
	/// <summary>
	/// Call to recalculate the direction.
	/// </summary>
	/// <returns><c>true</c>, if colliders were switched, <c>false</c> otherwise.</returns>
	virtual public bool UpdateDirection (RaycastCharacterController2D character) {
		int newDirection = 0;

		
		// Always return ledge hang dir - NEW
		if (character.IsLedgeHanging) {
			if (character.LedgeHangDirection == RC_Direction.RIGHT) newDirection = 1;
			if (character.LedgeHangDirection == RC_Direction.LEFT) newDirection =  -1;
		}
		if (character.characterInput.x > 0.0f) newDirection =  1;
		if (character.characterInput.x < 0.0f) newDirection =  -1;
		//if (character.Velocity.x > 0.0f) newDirection =  1;
		//if (character.Velocity.x < 0.0f) newDirection =  -1;
		
		// If PULLING then return oppoiste direction
		if (character.State == CharacterState.PULLING) newDirection *= -1;

		// Special case for startup
		if (CurrentDirection == 0 && newDirection != 0) {
			if (newDirection != startingDirection) SwitchColliders(character);
		}

		if (newDirection != 0 && newDirection != CurrentDirection) {
			SwitchColliders(character);
			CurrentDirection = newDirection;
			return true;
		}
		return false;
	}
 public override void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     if (collider.direction == RC_Direction.DOWN && !fallStarted) {
         fallStarted = true;
         StartCoroutine(Fall());
     }
 }
 public override void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     if (collider.direction == RC_Direction.DOWN) {
         characterIsOnMe = true;
         standTimer = standTime;
     }
 }
 override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     if (character.FallThroughTimer <= 0.0f && collider.direction == RC_Direction.DOWN && character.characterInput.dropFromPlatform)
     {
         character.FallThroughTimer = fallThroughTime;
     }
 }
Esempio n. 7
0
 void OnGUI()
 {
     controller   = (RaycastCharacterController)EditorGUILayout.ObjectField(controller, typeof(RaycastCharacterController), true);
     controller2D = (RaycastCharacterController2D)EditorGUILayout.ObjectField(controller2D, typeof(RaycastCharacterController2D), true);
     if (GUILayout.Button(new GUIContent("Recalculate Now", "Press to automatically generate values based on the controller and total height. Some tweaking may be needed.")))
     {
         DoCalculations();
     }
     totalLength  = NumberLabel("Total Length", totalLength, "Total ladder size in world units.");
     ladderWidth  = NumberLabel("Ladder Width", ladderWidth, "Width of the ladder in world units.");
     stepSize     = NumberLabel("Step Size", stepSize, "Size of each step.");
     stepDistance = NumberLabel("Step Distance", stepDistance, "Distance between each step.");
     useLadderTop = GUILayout.Toggle(useLadderTop, new GUIContent("Use Ladder Top", "Have a rigid top the user can stand on."));
     if (useLadderTop)
     {
         ladderTopDistance = NumberLabel("Ladder Top Offset", ladderTopDistance, "The offset from the top of the ladder in which the 'climb to top' animation is triggered.");
     }
     generateMesh = GUILayout.Toggle(generateMesh, new GUIContent("Generate View", "Instantiate a prefab for the ladders view and scale it to the ladder bounds."));
     if (generateMesh)
     {
         GUILayout.BeginHorizontal();
         GUILayout.Label("View Prefab", GUILayout.Width(100));
         GUILayout.FlexibleSpace();
         GUILayout.Box(new GUIContent("", "Select a prefab to use for the ladder view."), GUILayout.Width(100));
         meshPrefab = (GameObject)EditorGUI.ObjectField(GUILayoutUtility.GetLastRect(), meshPrefab, typeof(GameObject), false);
         GUILayout.EndHorizontal();
     }
     if (GUILayout.Button(new GUIContent("Generate Ladder", "Create the ladder!")))
     {
         GenerateLadder();
     }
 }
 override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     if (collider.direction == RC_Direction.DOWN)
     {
         character.Velocity = new Vector3(character.Velocity.x, springForce);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Respawn the character at the given point.
 /// </summary>
 public static void Respawn(RaycastCharacterController2D character)
 {
     if (currentRespawnPoint != null)
     {
         character.Velocity           = Vector2.zero;
         character.transform.position = currentRespawnPoint.myTransform.position + currentRespawnPoint.respawnPositionOffset;
     }
 }
Esempio n. 10
0
	override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		// Hitting from below
		if (collider.direction == RC_Direction.UP) {
			if (particles != null) particles.Play();
			myCollider.enabled = false;
			myRenderer.enabled = false;
		}
	}
 override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     if (collider.direction == RC_Direction.DOWN)
     {
         characterIsOnMe = true;
         standTimer      = standTime;
     }
 }
Esempio n. 12
0
	override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		if (character.StartedClimbing) {
			// Move off ladder
			if (control.dismountWithArrows && character.characterInput.x != 0.0f) {
				character.Dismount(this);
			}
		} 
	}
 override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     if (collider.direction == RC_Direction.DOWN && !fallStarted)
     {
         fallStarted = true;
         StartCoroutine(Fall());
     }
 }
 override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     // If we are standing on this
     if (!alreadyAdded && collider.direction == RC_Direction.DOWN)
     {
         character.SetDrag(drag);
         alreadyAdded = true;
     }
 }
Esempio n. 15
0
 void Start()
 {
     if (controller == null)
     {
         controller = GetComponent <RaycastCharacterController2D>();
     }
     // Register listeners
     controller.CharacterAnimationEvent += new RaycastCharacterController2D.CharacterControllerEventDelegate(CharacterAnimationEvent);
 }
Esempio n. 16
0
    /// <summary>
    /// Trigger the respawn.
    /// </summary>
    override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
    {
        SimpleHealth2D health = character.GetComponent <SimpleHealth2D>();

        if (health != null && health.Health > 0)
        {
            health.Die();
        }
    }
Esempio n. 17
0
	override public Transform ParentOnStand (RaycastCharacterController2D character) {
		if (rigidbody.velocity.y > velocityForFall) {
			return myTransform;
		}
		if (character.transform.parent != null) {
			character.Velocity = new Vector2 (character.Velocity.x, rigidbody.velocity.y);
			character.transform.parent = null;
		}
		return null;
	}
Esempio n. 18
0
 override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     if (character.StartedClimbing)
     {
         // Move off ladder
         if (control.dismountWithArrows && character.characterInput.x != 0.0f)
         {
             character.Dismount(this);
         }
     }
 }
Esempio n. 19
0
 override public Transform ParentOnStand(RaycastCharacterController2D character)
 {
     if ((character.StartedClimbing || character.characterInput.y < 0.0f))
     {
         actAsGround = false;
     }
     else
     {
         actAsGround = true;
     }
     return(transform);
 }
Esempio n. 20
0
 /// <summary>
 /// Initialise variables.
 /// </summary>
 void Start()
 {
     health = maxHealth;
     if (controller == null)
     {
         controller = gameObject.GetComponent <RaycastCharacterController2D>();
     }
     if (controller == null)
     {
         Debug.LogError("SimpleHealth script not attached to a character");
     }
 }
Esempio n. 21
0
 protected void Load()
 {
     if (controller == null)
     {
         controller = (RaycastCharacterController)FindObjectOfType(typeof(RaycastCharacterController));
     }
     if (controller2D == null)
     {
         controller2D = (RaycastCharacterController2D)FindObjectOfType(typeof(RaycastCharacterController2D));
     }
     DoCalculations();
 }
 override public Transform ParentOnStand(RaycastCharacterController2D character)
 {
     if (rigidbody.velocity.y > velocityForFall)
     {
         return(myTransform);
     }
     if (character.transform.parent != null)
     {
         character.Velocity         = new Vector2(character.Velocity.x, rigidbody.velocity.y);
         character.transform.parent = null;
     }
     return(null);
 }
Esempio n. 23
0
 override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     // Hitting from below
     if (collider.direction == RC_Direction.UP)
     {
         if (particles != null)
         {
             particles.Play();
         }
         myCollider.enabled = false;
         myRenderer.enabled = false;
     }
 }
Esempio n. 24
0
	override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		// Hitting from below (i.e. a headbutt)
		if (isActive && collider.direction == RC_Direction.UP) {
			StartCoroutine(DoHit());
			if (spawnGameObject != null && !hasSpawned) StartCoroutine(DoSpawn());
			else if (spawnGameObject != null) DoBobble();
		}
		// Kill enemies above 
		/*else if (!isActive && collider.direction == RC_Direction.DOWN && character is IEnemy) {
			((IEnemy)character).Kill();
		}
		*/
	}
Esempio n. 25
0
    /// <summary>
    /// Call to recalculate the direction.
    /// </summary>
    /// <returns><c>true</c>, if colliders were switched, <c>false</c> otherwise.</returns>
    virtual public bool UpdateDirection(RaycastCharacterController2D character)
    {
        int newDirection = 0;


        // Always return ledge hang dir - NEW
        if (character.IsLedgeHanging)
        {
            if (character.LedgeHangDirection == RC_Direction.RIGHT)
            {
                newDirection = 1;
            }
            if (character.LedgeHangDirection == RC_Direction.LEFT)
            {
                newDirection = -1;
            }
        }
        if (character.characterInput.x > 0.0f)
        {
            newDirection = 1;
        }
        if (character.characterInput.x < 0.0f)
        {
            newDirection = -1;
        }
        //if (character.Velocity.x > 0.0f) newDirection =  1;
        //if (character.Velocity.x < 0.0f) newDirection =  -1;

        // If PULLING then return oppoiste direction
        if (character.State == CharacterState.PULLING)
        {
            newDirection *= -1;
        }

        // Special case for startup
        if (CurrentDirection == 0 && newDirection != 0)
        {
            if (newDirection != startingDirection)
            {
                SwitchColliders(character);
            }
        }

        if (newDirection != 0 && newDirection != CurrentDirection)
        {
            SwitchColliders(character);
            CurrentDirection = newDirection;
            return(true);
        }
        return(false);
    }
Esempio n. 26
0
	override public Transform ParentOnStand(RaycastCharacterController2D character) {
		if (character.StartedClimbing) {
			// Not on the same rope
			if (!(character.MyParent is Ladder2D && ((Ladder2D)character.MyParent).control == control)) {
				// Centre on rope
				if (control.snapToMiddle) {
					float delta = myTransform.position.x - character.transform.position.x;
					character.transform.Translate(delta, 0.0f, 0.0f, Space.Self);
				}
			}
			return transform;
		}
		return null;
	}
 public void KillFromAbove(HitBox other, Collider me)
 {
     if (!hasHitPlayer && other != null && other.simplehealth != null)
     {
         // If we can find a character controller
         RaycastCharacterController2D hero = other.simplehealth.GetComponent <RaycastCharacterController2D>();
         if (hero != null)
         {
             me.collider.enabled = false;
             Kill();
             hero.Velocity = new Vector2(hero.Velocity.x, bounceVelocity);
         }
     }
 }
Esempio n. 28
0
 override public Transform ParentOnStand(RaycastCharacterController2D character)
 {
     if (character.StartedClimbing)
     {
         // Not on the same rope
         if (!(character.MyParent is Ladder2D && ((Ladder2D)character.MyParent).control == control))
         {
             // Centre on rope
             if (control.snapToMiddle)
             {
                 float delta = myTransform.position.x - character.transform.position.x;
                 character.transform.Translate(delta, 0.0f, 0.0f, Space.Self);
             }
         }
         return(transform);
     }
     return(null);
 }
    override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
    {
        // Hitting from below (i.e. a headbutt)
        if (isActive && collider.direction == RC_Direction.UP)
        {
            StartCoroutine(DoHit());
            if (spawnGameObject != null && !hasSpawned)
            {
                StartCoroutine(DoSpawn());
            }
            else if (spawnGameObject != null)
            {
                DoBobble();
            }
        }
        // Kill enemies above

        /*else if (!isActive && collider.direction == RC_Direction.DOWN && character is IEnemy) {
         *      ((IEnemy)character).Kill();
         * }
         */
    }
 override public Transform ParentOnStand(RaycastCharacterController2D character)
 {
     return(myTransform);
 }
Esempio n. 31
0
	/// <summary>
	/// Stand on a respawn point to activate it. You could play a particle effect of something here.
	/// </summary>
	override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		if (collider.direction == RC_Direction.DOWN) currentRespawnPoint = this;
	}
Esempio n. 32
0
	/// <summary>
	/// Does this platform want to have this platform become the characters parent. Used for moving platforms.
	/// </summary>
	/// <returns>
	/// Return a transform if you want to reparent the character.
	/// </returns>
	virtual public Transform ParentOnStand(RaycastCharacterController2D character) {
		return null;	
	}
Esempio n. 33
0
	void Start(){
		if (controller == null) controller = GetComponent<RaycastCharacterController2D>();
		// Register listeners
		controller.CharacterAnimationEvent += new RaycastCharacterController2D.CharacterControllerEventDelegate (CharacterAnimationEvent);
		
	}
Esempio n. 34
0
	override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		if (character.FallThroughTimer <= 0.0f && collider.direction == RC_Direction.DOWN && character.characterInput.dropFromPlatform) {
			character.FallThroughTimer = fallThroughTime;
		}
	}
 void OnGUI()
 {
     controller = (RaycastCharacterController) EditorGUILayout.ObjectField(controller, typeof(RaycastCharacterController), true);
     controller2D = (RaycastCharacterController2D) EditorGUILayout.ObjectField(controller2D, typeof(RaycastCharacterController2D), true);
     if (GUILayout.Button (new GUIContent("Recalculate Now", "Press to automatically generate values based on the controller and total height. Some tweaking may be needed."))){
         DoCalculations();
     }
     totalLength = NumberLabel("Total Length", totalLength, "Total ladder size in world units.");
     ladderWidth = NumberLabel("Ladder Width", ladderWidth, "Width of the ladder in world units.");
     stepSize = NumberLabel("Step Size", stepSize, "Size of each step.");
     stepDistance = NumberLabel("Step Distance", stepDistance, "Distance between each step.");
     useLadderTop = GUILayout.Toggle(useLadderTop, new GUIContent("Use Ladder Top", "Have a rigid top the user can stand on."));
     if (useLadderTop) ladderTopDistance = NumberLabel("Ladder Top Offset", ladderTopDistance, "The offset from the top of the ladder in which the 'climb to top' animation is triggered.");
     generateMesh = GUILayout.Toggle(generateMesh, new GUIContent("Generate View", "Instantiate a prefab for the ladders view and scale it to the ladder bounds."));
     if (generateMesh) {
         GUILayout.BeginHorizontal();
         GUILayout.Label("View Prefab", GUILayout.Width(100));
         GUILayout.FlexibleSpace();
         GUILayout.Box (new GUIContent("", "Select a prefab to use for the ladder view."), GUILayout.Width(100));
         meshPrefab = (GameObject) EditorGUI.ObjectField(GUILayoutUtility.GetLastRect(), meshPrefab, typeof(GameObject), false);
         GUILayout.EndHorizontal();
     }
     if (GUILayout.Button (new GUIContent("Generate Ladder", "Create the ladder!"))) {
         GenerateLadder();
     }
 }
 protected void Load()
 {
     if (controller == null) controller = (RaycastCharacterController) FindObjectOfType(typeof(RaycastCharacterController));
     if (controller2D == null) controller2D = (RaycastCharacterController2D) FindObjectOfType(typeof(RaycastCharacterController2D));
     DoCalculations();
 }
Esempio n. 37
0
 /// <summary>
 /// Does this platform want to have this platform become the characters parent. Used for moving platforms.
 /// </summary>
 /// <returns>
 /// Return a transform if you want to reparent the character.
 /// </returns>
 virtual public Transform ParentOnStand(RaycastCharacterController2D character)
 {
     return(null);
 }
Esempio n. 38
0
 /// <summary>
 /// This is called when a platform is hit. Override to implement platform behaviour.
 /// </summary>
 /// <param name='collider'>
 /// The collider that did the hitting.
 /// </param>
 /// <param name='character'>
 /// The character that did the hitting.
 /// </param>
 virtual public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character)
 {
     // Do nothing
 }
Esempio n. 39
0
 /// <summary>
 /// Gets the animation for the character. Only called if you have set overrideAnimation to true.
 /// </summary>
 /// <returns>
 /// The animation state.
 /// </returns>
 virtual public CharacterState GetAnimationState(RaycastCharacterController2D character)
 {
     return(CharacterState.IDLE);
 }
Esempio n. 40
0
	/// <summary>
	/// Initialise variables.
	/// </summary>
	void Start () {
		health = maxHealth;
		if (controller == null) controller = gameObject.GetComponent<RaycastCharacterController2D>();
		if (controller == null) Debug.LogError("SimpleHealth script not attached to a character");
	}
Esempio n. 41
0
	override public Transform ParentOnStand(RaycastCharacterController2D character) {
		return myTransform;	
	}
Esempio n. 42
0
	/// <summary>
	/// Is the character at the appropriate height to trigger the climb top of ladder state.
	/// </summary>
	virtual public bool ShouldPlayLedgeClimb (RaycastCharacterController2D character) {
		return !disableLedgeClimb && character.transform.position.y > ledgeClimbHeight;
	}
Esempio n. 43
0
	/// <summary>
	/// Trigger the respawn.
	/// </summary>
	override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		SimpleHealth2D health = character.GetComponent<SimpleHealth2D>();
		if (health != null && health.Health > 0) {
			health.Die ();
		}
	}
Esempio n. 44
0
 /// <summary>
 /// Is the character at the appropriate height to trigger the climb top of ladder state.
 /// </summary>
 virtual public bool ShouldPlayLedgeClimb(RaycastCharacterController2D character)
 {
     return(!disableLedgeClimb && character.transform.position.y > ledgeClimbHeight);
 }
Esempio n. 45
0
	override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		if (collider.direction == RC_Direction.DOWN) {
			character.Velocity = new Vector3(character.Velocity.x, springForce);
		}
	}
Esempio n. 46
0
	/// <summary>
	/// This is called when a platform is hit. Override to implement platform behaviour.
	/// </summary>
	/// <param name='collider'>
	/// The collider that did the hitting.
	/// </param>
	/// <param name='character'>
	/// The character that did the hitting.
	/// </param>
	virtual public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) {
		// Do nothing
	}
Esempio n. 47
0
	virtual protected void SwitchColliders(RaycastCharacterController2D character) {
		character.SwitchColliders ();
	}
Esempio n. 48
0
	/// <summary>
	/// Gets the animation for the character. Only called if you have set overrideAnimation to true.
	/// </summary>
	/// <returns>
	/// The animation state.
	/// </returns>
	virtual public CharacterState GetAnimationState(RaycastCharacterController2D character) {
		return CharacterState.IDLE;
	}
Esempio n. 49
0
	/// <summary>
	/// Respawn the character at the given point.
	/// </summary>
	public static void Respawn(RaycastCharacterController2D character) {
		if (currentRespawnPoint != null) {
			character.Velocity = Vector2.zero;
			character.transform.position = currentRespawnPoint.myTransform.position + currentRespawnPoint.respawnPositionOffset;
		}
	}
Esempio n. 50
0
 virtual protected void SwitchColliders(RaycastCharacterController2D character)
 {
     character.SwitchColliders();
 }
Esempio n. 51
0
	override public Transform ParentOnStand(RaycastCharacterController2D character) {
		if ((character.StartedClimbing || character.characterInput.y < 0.0f)) actAsGround = false;
		else actAsGround = true;
		return transform;
	}