- Home /
Collider points one frame old in OnTriggerStay2D
Hello, Im detecting collision inside the method OnTriggerStay2D from 2 PolygonCollider2D-s. Problem is, the moving collider's points are 1 frame old. See the image - magenta(PolygonCollider2D.points) dots have not moved to the same position as the rock's collider has.
Is there a way to fix this so the collider points would actually reflect the actual position of the collider?
Here is the code I use on the collision:
void Update () {
transform.Translate(-Vector2.up * Time.deltaTime / 1f);
}
void OnTriggerStay2D(Collider2D other) {
var points = GetComponent<PolygonCollider2D>().points;
foreach (Vector2 point in points) {
Vector2 mostRightPoint = transform.TransformPoint(point);
Utils.DrawPoint(mostRightPoint, Color.magenta, null);
}
Debug.Break();
}
Answer by eits · May 28, 2015 at 08:19 PM
So it turns out Update gets called after OnTriggerStay2D. Thats why the collision points are off.
Now Im doing my collision calculations in LateUpdate() where all is in sync.
Your answer
Follow this Question
Related Questions
PolygonCollider2d Use Z Axis 0 Answers
OnTriggerEnter 's Not called at startup? 2 Answers
Getting multiple Polygon Collider 2D on script 2 Answers
Adding child Colliders to your parent object's OnTriggerStay 1 Answer
physics.OverlapSphere colliders 1 Answer