I am in the process of creating my first game which is a very simple remake of the ZX Spectrum game Fred. I have stumbled on my first issue and it relates to the activation of the Box Collider.
To break this down for you:
Fred can successfully climb up and down ladders. Fred has both a Box Collider 2D and Circle Collider 2D. The Circle Collider 2D encapsulates the overall size of the sprite/character. The Box Collider 2D is the size of a small strip reaching the height of the sprite/character.
See Fred Sprite below:
The Ladder, which is essentially a rope, has a Box Collider 2D which also encapsulates the sprites shape's width and height.
See Rope Sprite below:
The reason for assigning both a Box Collider 2D and Circle Collider 2D to Fred is because when an enemy attacks, i want the attack to impact the Circle Collider 2D, as this affects the general width of Fred.
The Box Collider 2D is a narrow strip assigned to the center of the character. The reason for this is for when Fred approaches the Rope Sprite, he changes animation from walk to climb. Fred can climb the Rope whether the Box Collider 2D or Circle Collider 2D are activated, however i want the Box Collider 2D to take precedence when Fred approaches and climbs the Rope Sprite.
I am using OnTriggerEnter2D for the character to successfully interact with the rope, See below the code which i have assigned to the Rope Sprite:
`
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Ladder"))
{
isLadder = true;
isClimbing = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.CompareTag("Ladder"))
{
isLadder = false;
isClimbing = false;
}
}
`
Because i am limited in my knowledge of c# i am trying to find a way to code around the Circle Collider 2D and activate the Box Collider 2D for when the character approaches the rope and climbs either up or down.
I have attempted to apply OnCollisonEnter() however this overrides OnCollisionEnter2D and deactivates Rope Climbing.