How to create an object that mirrors players movements?
Hello sorry I am a novice in Unity 2D and need a little guidance. I currently have a ball that moves on release of mouse button via a spring joint. Is it possible to have a mirror ball that moves in the opposite direction of the ball that starts on the opposite side? If it is what is the best practise to achieve this?
The code below is the movement method used on the ball.
public Rigidbody2D rb;
public float releaseTime = .15f;
public float constantSpeed = 10f;
private bool isPressed = false;
void Start() {
}
void Update ()
{
if (isPressed) {
rb.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
rb.velocity = constantSpeed * (rb.velocity.normalized);
}
void OnMouseDown ()
{
isPressed = true;
rb.isKinematic = true;
}
void OnMouseUp ()
{
isPressed = false;
rb.isKinematic = false;
StartCoroutine (Release ());
}
IEnumerator Release ()
{
yield return new WaitForSeconds (releaseTime);
GetComponent<SpringJoint2D> ().enabled = false;
}
Comment