#How top detect collisions from the side of a tilemap
1 messages · Page 1 of 1 (latest)
'''void OnCollisionEnter2D(Collision2D col)
{
Debug.Log("Collision Enemy:" + col.gameObject.tag);
if (col.gameObject.CompareTag("Ground"))
{
Vector3 dir = (col.gameObject.transform.position - gameObject.transform.position).normalized;
if (dir.x > 0)
{
// hit right
bIsGoingRight = !bIsGoingRight;
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
}
else if (dir.x < 0)
{
// hit left
bIsGoingRight = !bIsGoingRight;
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
}
}
'''
!code
Posting code
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
@rapid lion
i know, i'm trying to fix it