two objects with collider 2d are not colliding.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float speed = 10;
public float y_moving = 0f;
public float jump_power = 0f;
public float gravity = 2f;
CircleCollider2D colider;
// Start is called before the first frame update
void Start()
{
colider = gameObject.GetComponent<CircleCollider2D>();
}
// Update is called once per frame
void Update()
{
bool isGrounded = colider.IsTouchingLayers(8);
if (isGrounded) // if grounded
{
y_moving = gravity * Time.deltaTime;
}
if (Input.GetKey(KeyCode.Space) & isGrounded)
{
y_moving = jump_power;
}
y_moving -= gravity * Time.deltaTime;
float x_moving = Input.GetAxisRaw("Horizontal");
x_moving *= Time.deltaTime;
x_moving *= speed;
transform.position += new Vector3(x_moving, y_moving, 0);
print(colider.IsTouchingLayers(LayerMask.GetMask("Ground")));
}
}
Here is my code.
The last line never prints True, even if there are ground layers overlapping the colliders