basically I have created a object name square that functions as a basic character controller. when I press and the square the jump button it jumps. i created a trigger which is another game object that simply follows the square around.
I added the ontriggerenter and ontriggerexit functions so that it would mark the grounded variable as true whenever the ground is touched. For some reason this will not work. I can mark the grounded variable as true without the use of the oncollisionenter function and it works fine, if i just have the grounded variable always marked as true the movement works fine. so i have deducted that the issue is in teh oncollsionenter function. Does anybody have a solution for this?
public class FollowPlayer : MonoBehaviour
{
public character_controller square;
// Update is called once per frame
void Update()
{
transform.position = GameObject.Find(“Square”).transform.position;
//this was done to test if the issue i had was with marking the variable true. i can change the grounded vairable’s value easily
if (Input.GetKeyDown(KeyCode.U))
{
square.grounded = true;
Debug.Log(“pressed U key and can now jump”);
}
}
private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag("Ground"))
{
square.grounded = true;
Debug.Log("grounded");
}
}
private void OnCollisionExit2D(Collision2D col)
{
if (col.gameObject.CompareTag("Ground"))
{
square.grounded = false;
Debug.Log("airborne");
}
}
}