Creating an EdgeCollider2D with trail coordinates
Hi Guys,
I'm currently creating an Edge Collider 2D based on the coordinates I passed with the Player/GameObject.
My Problem is that the EdgeCollider I create is then off to the trail of the Gameobject (see Attached Picture with trail and green line). It also happens when I use directly the coordinates of the trail to create the EdgeCollider 2D. It seems it scales worse with higher distance. I also had to correct the starting position by subtracting transform.position. I assumed list pointList would contain Global Position Vectors and this wouldn't be needed. Is there any Position Concept I don't know/understand? The Script is attached to the TrailObject which is attached to the GameObject (a ship sprite). All Input would help me.
With best Regards, Markus
private EdgeCollider2D col;
private TrailRenderer tr;
void SetPointsYourself()
{
pointList.Add(transform.position);
setEdge();
}
private void setEdge()
{
col.Reset();
List<Vector2> tempList = new List<Vector2>();
for (int i = 0; i < pointList.Count; i++) {
tempList.Add(pointList[i] - new Vector2(transform.position.x, transform.position.y));
}
col.points = tempList.ToArray();
col.transform.rotation = Quaternion.Euler(0, 0, 0);
}
Answer by Siliko · Oct 05, 2020 at 01:23 PM
Hi !
Maybe Try transform.localPosition instead of transform.position, it returns the worldPosition instead of the position relative to parent if i'm not wrong.
Your answer
Follow this Question
Related Questions
Is it possible to know the angle of collider2D border in touch place with RigidBody2D? 1 Answer
Problems with OnTriggerEnter2D, Colliders and Triggers 1 Answer
Tilemap Collision 2D colliding with ground. 0 Answers
Spawn prefab randomly over polygon collider 2d 0 Answers
help needed on tilemap collider 0 Answers