Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Using this SO questionthis SO question we can determine where the collision was. We can then modify our code to be

Using this SO question we can determine where the collision was. We can then modify our code to be

Using this SO question we can determine where the collision was. We can then modify our code to be

added 12 characters in body
Source Link
Liam McInroy
  • 391
  • 1
  • 4
  • 15
void OnCollisionEnter2D(Collision2D col) {
    transformvar relativePosition = transform.InverseTransformPoint(collisioncol.contacts);
    if (abs(relativePosition.position.x) > abs(relativePosition.position.y))
        testing.speedX = 0;
    else
        testing.speedY = 0;
}

void OnCollisionExit2D(Collision2D col) {
    testing.speedY = 10F;
    testing.speedX = 10F;
}
void OnCollisionEnter2D(Collision2D col) {
    transform relativePosition = transform.InverseTransformPoint(collision.contacts);
    if (abs(relativePosition.x) > abs(relativePosition.y))
        testing.speedX = 0;
    else
        testing.speedY = 0;
}

void OnCollisionExit2D(Collision2D col) {
    testing.speedY = 10F;
    testing.speedX = 10F;
}
void OnCollisionEnter2D(Collision2D col) {
    var relativePosition = transform.InverseTransformPoint(col.contacts);
    if (abs(relativePosition.position.x) > abs(relativePosition.position.y))
        testing.speedX = 0;
    else
        testing.speedY = 0;
}

void OnCollisionExit2D(Collision2D col) {
    testing.speedY = 10F;
    testing.speedX = 10F;
}
added 613 characters in body
Source Link
Liam McInroy
  • 391
  • 1
  • 4
  • 15

###Edit 2

Using this SO question we can determine where the collision was. We can then modify our code to be

void OnCollisionEnter2D(Collision2D col) {
    transform relativePosition = transform.InverseTransformPoint(collision.contacts);
    if (abs(relativePosition.x) > abs(relativePosition.y))
        testing.speedX = 0;
    else
        testing.speedY = 0;
}

void OnCollisionExit2D(Collision2D col) {
    testing.speedY = 10F;
    testing.speedX = 10F;
}

###Edit 2

Using this SO question we can determine where the collision was. We can then modify our code to be

void OnCollisionEnter2D(Collision2D col) {
    transform relativePosition = transform.InverseTransformPoint(collision.contacts);
    if (abs(relativePosition.x) > abs(relativePosition.y))
        testing.speedX = 0;
    else
        testing.speedY = 0;
}

void OnCollisionExit2D(Collision2D col) {
    testing.speedY = 10F;
    testing.speedX = 10F;
}
added 1209 characters in body
Source Link
Liam McInroy
  • 391
  • 1
  • 4
  • 15
Loading
Source Link
Liam McInroy
  • 391
  • 1
  • 4
  • 15
Loading