- Home /
[FIXED.]I can't make the bool = false when I exit the collision (OntriggerExit2D)
This is the climbing tree code.
Help me please. Already set the animation bool climbingCheck = true when enter the collision but it does not false on exit the tree collision(2d). Sorry for my noob English too.
Where should I put climbingCheck = false; on the code part? .......................................
void Update()
{
//use for space spcaebar 1 time to highest jump.
//Input.GetAxis("Jump")>0 use for hold space bar to jump higher until max.
if (grounded && Input.GetButtonDown("Jump"))
{
audiox.PlayOneShot(Jump, 0.3f);
grounded = false;
anim.SetBool("isGrounded", grounded);
rigid2d.AddForce(new Vector2(0, jumpHeight));
}
if (canClimb)
{
//CLIMB UP
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
anim.SetBool("climbingCheck", climbingCheck);
//rigid2d.velocity = new Vector2(0, climbspeed);
climbingCheck = true;
climbing = true;
transform.Translate(Vector2.up * 0.5f * Time.deltaTime);
rigid2d.isKinematic = true;
rigid2d.velocity = new Vector2(0, 0);
//CLIMB Animation
anim.SetFloat("Direction", 1);
OnLadder = true;
anim.enabled = true;
maxSpeed = 0.7f;
if (!facingRight)
{
flip();
return;
}
canClimDown = true;
}
else if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow))
{
anim.enabled = false;
}else
{
climbingCheck = false;
}
if (canClimDown)
{
//CLIMB DOWN
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow) && rigid2d.isKinematic == true)
{
climbing = true;
transform.Translate(Vector2.down * 0.5f * Time.deltaTime);
anim.SetFloat("Direction", -1);
anim.Play("Player_climbing", -1, float.NegativeInfinity);
OnLadder = true;
// rigid2d.velocity = new Vector2(0, -0.48f);
anim.enabled = true;
}
else if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow))
{
anim.enabled = false;
}
}else
{
climbingCheck = false;
}
}
if(canClimb == false)
{
rigid2d.isKinematic = false;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "LadderStart")
{
canClimb = true;
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "LadderStart")
{
canClimb = false;
//rigid2d.isKinematic = false;
anim.enabled = true;
climbingCheck = false;
}
}
I did set. The bool = true when I enter the collision but when I exit it do not set to false.
I don't understand. What do you exactly want to do? Please explain in details...
When you're testing this out, do you let go of W or Up before leaving the collider?
Additionally, can you try doing this: if(canClimb == false) { rigid2d.is$$anonymous$$inematic = false; climbingCheck = false; } on line 78?
Answer by nu51313932 · Oct 21, 2017 at 04:11 AM
FIXED.
I need to put anim.setbool....
in function OnTriggerExit2D
Your answer
![](https://koobas.hobune.stream/wayback/20220612141456im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnTriggerEnter and Exit seem to not be working 1 Answer
Question regarding OnTriggerExit2D for destroyed objects 1 Answer
Why is OnTriggerExit2D called before OnTriggerEnter2D? 1 Answer
Unity3D: Entering a trigger disables a few bools for no reason 2 Answers
OnTriggerExit2D not working on android (but works in editor) 0 Answers