Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
fixed the title
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 55
  • 61

(Unity) - How can I assign a layer to tiles on an individual level? (Closed)

I've just started out with my first game in Unity. It's a simple 2D Platformer with a tile-based level.   

enter image description here When

When coding in the movement, I used the Physics2D.OverlapCircle() and an empty to check whether my player was touching the ground. However, I need to use a layer to make sure only the ground is detected.

my code below

//fixed update used for physics calculations
void FixedUpdate()
{
    //right or left arrows being pressed
    float moveX = Input.GetAxis("Horizontal");

    Vector2 moveDir = new Vector2(moveX * playerSpeed, rb.velocity.y);
    rb.velocity = moveDir;
}
 
//update used for spacebar input and force
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space)) 
    {
        rb.velocity = Vector2.up * jumpForce*Time.deltaTime;
    }
    
    //is my circle overlapping any other colliders
    Collider2D collider =  Physics2D.OverlapCircle(feet.position, checkRadius, groundLayer);
    Debug.Log(collider); 
}

end of code

When I tried assigning layers to my tiles, I couldn't find a way to do it. I

I would be really grateful if anyone could show me how to, or if anyone can tell me a more efficient way to deal with jumping in a 2D platformer. Thanks

EDIT: Thank you everyone for their help!

[![Game Scene View][2]][2]

(Unity) - How can I assign a layer to tiles on an individual level? (Closed)

I've just started out with my first game in Unity. It's a simple 2D Platformer with a tile-based level.  enter image description here When coding in the movement, I used the Physics2D.OverlapCircle() and an empty to check whether my player was touching the ground. However, I need to use a layer to make sure only the ground is detected.

my code below

//fixed update used for physics calculations
void FixedUpdate()
{
    //right or left arrows being pressed
    float moveX = Input.GetAxis("Horizontal");

    Vector2 moveDir = new Vector2(moveX * playerSpeed, rb.velocity.y);
    rb.velocity = moveDir;
}
 
//update used for spacebar input and force
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space)) 
    {
        rb.velocity = Vector2.up * jumpForce*Time.deltaTime;
    }
    
    //is my circle overlapping any other colliders
    Collider2D collider =  Physics2D.OverlapCircle(feet.position, checkRadius, groundLayer);
    Debug.Log(collider); 
}

end of code

When I tried assigning layers to my tiles, I couldn't find a way to do it. I would be really grateful if anyone could show me how to, or if anyone can tell me a more efficient way to deal with jumping in a 2D platformer. Thanks

EDIT: Thank you everyone for their help!

[![Game Scene View][2]][2]

How can I assign a layer to tiles on an individual level?

I've just started out with my first game in Unity. It's a simple 2D Platformer with a tile-based level. 

enter image description here

When coding in the movement, I used the Physics2D.OverlapCircle() and an empty to check whether my player was touching the ground. However, I need to use a layer to make sure only the ground is detected.

my code below

//fixed update used for physics calculations
void FixedUpdate()
{
    //right or left arrows being pressed
    float moveX = Input.GetAxis("Horizontal");

    Vector2 moveDir = new Vector2(moveX * playerSpeed, rb.velocity.y);
    rb.velocity = moveDir;
}
 
//update used for spacebar input and force
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space)) 
    {
        rb.velocity = Vector2.up * jumpForce*Time.deltaTime;
    }
    
    //is my circle overlapping any other colliders
    Collider2D collider =  Physics2D.OverlapCircle(feet.position, checkRadius, groundLayer);
    Debug.Log(collider); 
}

When I tried assigning layers to my tiles, I couldn't find a way to do it.

I would be really grateful if anyone could show me how to, or if anyone can tell me a more efficient way to deal with jumping in a 2D platformer.

added 42 characters in body; edited title
Source Link

(Unity) - How can I assign a layer to tiles on an individual level? (Closed)

I've just started out with my first game in Unity. It's a simple 2D Platformer with a tile-based level. enter image description here When coding in the movement, I used the Physics2D.OverlapCircle() and an empty to check whether my player was touching the ground. However, I need to use a layer to make sure only the ground is detected.

my code below

//fixed update used for physics calculations
void FixedUpdate()
{
    //right or left arrows being pressed
    float moveX = Input.GetAxis("Horizontal");

    Vector2 moveDir = new Vector2(moveX * playerSpeed, rb.velocity.y);
    rb.velocity = moveDir;
}
 
//update used for spacebar input and force
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space)) 
    {
        rb.velocity = Vector2.up * jumpForce*Time.deltaTime;
    }
    
    //is my circle overlapping any other colliders
    Collider2D collider =  Physics2D.OverlapCircle(feet.position, checkRadius, groundLayer);
    Debug.Log(collider); 
}

end of code

When I tried assigning layers to my tiles, I couldn't find a way to do it. I would be really grateful if anyone could show me how to, or if anyone can tell me a more efficient way to deal with jumping in a 2D platformer. Thanks

EDIT: Thank you everyone for their help!

[![Game Scene View][2]][2]

(Unity) - How can I assign a layer to tiles on an individual level?

I've just started out with my first game in Unity. It's a simple 2D Platformer with a tile-based level. enter image description here When coding in the movement, I used the Physics2D.OverlapCircle() and an empty to check whether my player was touching the ground. However, I need to use a layer to make sure only the ground is detected.

my code below

//fixed update used for physics calculations
void FixedUpdate()
{
    //right or left arrows being pressed
    float moveX = Input.GetAxis("Horizontal");

    Vector2 moveDir = new Vector2(moveX * playerSpeed, rb.velocity.y);
    rb.velocity = moveDir;
}
 
//update used for spacebar input and force
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space)) 
    {
        rb.velocity = Vector2.up * jumpForce*Time.deltaTime;
    }
    
    //is my circle overlapping any other colliders
    Collider2D collider =  Physics2D.OverlapCircle(feet.position, checkRadius, groundLayer);
    Debug.Log(collider); 
}

end of code

When I tried assigning layers to my tiles, I couldn't find a way to do it. I would be really grateful if anyone could show me how to, or if anyone can tell me a more efficient way to deal with jumping in a 2D platformer. Thanks

[![Game Scene View][2]][2]

(Unity) - How can I assign a layer to tiles on an individual level? (Closed)

I've just started out with my first game in Unity. It's a simple 2D Platformer with a tile-based level. enter image description here When coding in the movement, I used the Physics2D.OverlapCircle() and an empty to check whether my player was touching the ground. However, I need to use a layer to make sure only the ground is detected.

my code below

//fixed update used for physics calculations
void FixedUpdate()
{
    //right or left arrows being pressed
    float moveX = Input.GetAxis("Horizontal");

    Vector2 moveDir = new Vector2(moveX * playerSpeed, rb.velocity.y);
    rb.velocity = moveDir;
}
 
//update used for spacebar input and force
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space)) 
    {
        rb.velocity = Vector2.up * jumpForce*Time.deltaTime;
    }
    
    //is my circle overlapping any other colliders
    Collider2D collider =  Physics2D.OverlapCircle(feet.position, checkRadius, groundLayer);
    Debug.Log(collider); 
}

end of code

When I tried assigning layers to my tiles, I couldn't find a way to do it. I would be really grateful if anyone could show me how to, or if anyone can tell me a more efficient way to deal with jumping in a 2D platformer. Thanks

EDIT: Thank you everyone for their help!

[![Game Scene View][2]][2]

Source Link

(Unity) - How can I assign a layer to tiles on an individual level?

I've just started out with my first game in Unity. It's a simple 2D Platformer with a tile-based level. enter image description here When coding in the movement, I used the Physics2D.OverlapCircle() and an empty to check whether my player was touching the ground. However, I need to use a layer to make sure only the ground is detected.

my code below

//fixed update used for physics calculations
void FixedUpdate()
{
    //right or left arrows being pressed
    float moveX = Input.GetAxis("Horizontal");

    Vector2 moveDir = new Vector2(moveX * playerSpeed, rb.velocity.y);
    rb.velocity = moveDir;
}
 
//update used for spacebar input and force
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space)) 
    {
        rb.velocity = Vector2.up * jumpForce*Time.deltaTime;
    }
    
    //is my circle overlapping any other colliders
    Collider2D collider =  Physics2D.OverlapCircle(feet.position, checkRadius, groundLayer);
    Debug.Log(collider); 
}

end of code

When I tried assigning layers to my tiles, I couldn't find a way to do it. I would be really grateful if anyone could show me how to, or if anyone can tell me a more efficient way to deal with jumping in a 2D platformer. Thanks

[![Game Scene View][2]][2]