Hello,
I am having a problem while trying to show two objects together with a joint. I have three sprites, two character’s ships and a metal bar that joins them together.
I have this code in the lady´s ship to join the Game Object Metal Joint (j), to the Lady’s Ship, and then to the Sir´s Ship.
public GameObject j;
public GameObject sir;
void FixedUpdate () {
j.transform.position = new Vector3(transform.position.x,transform.position.y,0.0f);
float dx = transform.position.x-sir.transform.position.x;
float dy = transform.position.y-sir.transform.position.y;
float dist = Mathf.Sqrt(dx*dx + dy*dy);
angle = Mathf.Asin(dy/dist);
j.transform.eulerAngles = new Vector3(0,0,-angle*180/Mathf.PI);
}
And it works very well for when the Sir character is on the Right Side of the screen, the joint angle changes according to his position. Like this:
But when the sir ship, moves to the other side… this happens
As you can see the joint connection is still at the correct height, but it does not rotate to the correct side.
How can I fix this?