Objects generating in unexpected position.
I'm using a player drawn lineRenderer as a collision object. It's static and has a PolygonCollider2D attached to it. In the OnCollisionEnter2D method I have the following to destroy the incoming line and generate a new one to simulate a reflection style event.
GameObject lineGO = PhotonNetwork.Instantiate("Line", transform.position, Quaternion.identity);
Line newLine = lineGO.GetComponent<Line>();
Debug.Log("collision point: " + collision.GetContact(0).point);
Vector2 reflectVector = Vector2.Reflect(collision.otherRigidbody.velocity, collision.GetContact(0).normal);
Debug.Log("reflect vector: " + reflectVector);
newLine.points = new List<Vector2>();
newLine.SetPoint(collision.GetContact(0).point + reflectVector);
newLine.SetPoint(collision.GetContact(0).point);
Regarding the image attached, the Orange bordered line contains the polygon collider. The Blue arrow represents the incoming vector of the projectile, and the short yellow-black is the reflected projectile generated by the code snippet above. The logging I have in the SetPoint method shows that the new projectile (which is a lineRenderer) is being drawn at the two points indicated by Red dots. However it is actually appearing where you see it in the image (minus a small amount of movement before I could hit the pause button).
I'm new to Unity and would love any help or suggestions that you all could provide.
Edit: The setPoint method referenced above
void SetPoint(Vector2 point) {
points.Add(point);
Debug.Log("SetPoint: " + point);
lineRenderer.positionCount = points.Count;
lineRenderer.SetPosition(points.Count - 1, point);
}
Your answer
Follow this Question
Related Questions
How do I get objects to detect collisions? 2 Answers
OnTriggerEnter getting called more than once 0 Answers
Can't make the player attack an enemy 0 Answers
Trying to get bool statement to work in OnTriggerStay2D 1 Answer
Is it possible to control prevent/enable colisions based on the value of a variable. 2 Answers