I am currently having problems with my character controller “jumping” when it collides against a wall. My wall jumping is based off of Megaman X series, if you need a reference.
What i want my jump to do is that when i collide with an object with the tag “wall”, the character controller first turns around 180 degrees to look the other way, then he will slow down as the person would be “grabbing” the wall, and then if the player says to jump, the charactercontroller would then jump.
My problem however is detecting the collisions between all these. When i use OnControllerColliderHit, it is an active call that contioussly checks / changes variables. However, when i try to use OnCollsionEnter / OnCollision Exit, it doesnt seem to actually call any collisions.
Any help would be great. Ill try to post my code so far (I have a lot more, but it would just confuse everyone).
void OnControllerColliderHit(ControllerColliderHit m_collider)
{
if(m_collider.gameObject.tag == "Wall")
{
if(Input.GetButtonDown("Jump"))
{
moveDirection.z = -30; //move the Character 30 units back, and then 10 units up, to
moveDirection.y = 10; //simulate him jumping off of a wall, and then up
transform.Rotate(new Vector3(0,180,0));
}
}
}
void OnTriggerEnter(Collider m_collider)
{
if(m_collider.gameObject.tag == "Wall")
{
Debug.Log("Hit Wall!");
Vector3 tempRotation = transform.eulerAngles; //rotate character 180 to face the other direction
tempRotation.y =180;
transform.eulerAngles = tempRotation;
}
}}
Does it still call the OnCollisionEnter() function? Because I looked at the reference place and it said that if it had a rigidbody and the iskinematic is turned off. If thats not the case, then that should fix most if not all of my problems.
Ok, to answer my own question, it seems that to do use collision detecting, you cannot have iskinematic on. What i did instead was freeze the position and rotation, which works as well.
So, it seems for now i have found a solution. What i have done is added a trigger collider to the player object. On my wall, i have the positon and rotation frozen, and made the collision detection in the rigidbody “continuous.” Without that it didnt work. Then in my code I called for an OnTriggerEnter, and it seems to work. Heres my code if anyone would happen to need it.
void OnControllerColliderHit(ControllerColliderHit m_collider)
{
if(m_collider.gameObject.tag == "Wall")
{
if(Input.GetButtonDown("Jump"))
{
moveDirection.z = -50; //move the Character 50 units back, and then 20 units up, to
moveDirection.y = 20; //simulate him jumping off of a wall, and then up
transform.Rotate(new Vector3(0,180,0));
}
}
}
void OnTriggerEnter(Collider m_collision)
{
if(m_collision.gameObject.tag == "Wall")
{
Debug.Log("Hit Wall!");
Vector3 tempRotation = transform.eulerAngles; //rotate character 180 to face the other direction
tempRotation.y = 180;
transform.eulerAngles = tempRotation;
isWallJumping = true; //later slows downt he charcter when on the wall
}
}
void OnTriggerExit(Collider m_collision)
{
if(m_collision.gameObject.tag == "Wall")
{
Debug.Log("Left Wall!");
isWallJumping = false; //allows the character to speed up when off the wall later in code
}
}