- Home /
Question by
AdsMindfreakstudios · Aug 06, 2018 at 09:16 AM ·
2danchorspringjointspring joint
Change springjoint2D connected anchor to where the player is facing (Y-axis)
the player is moving up always when the Fire(Method is called) even when the y-axis on right or left or any angle. i am trying to create controls so my player can swing in any direction upwards.
here is my code:
void Fire ()
{
Vector2 anchorPosition = new Vector2 (ropeShooter.transform.localPosition.x,
ropeShooter.transform.localPosition.y + 1.2f);
Vector2 anchorPosition1;
anchorPosition1.x = ropeShooter.transform.localPosition.x;
anchorPosition1.y = ropeShooter.transform.localPosition.y + 1.2f;
Vector3 position = ropeShooter.transform.position;
Vector3 direction = new Vector3 (ropeShooter.transform.localPosition.x, ropeShooter.transform.localPosition.y, ropeShooter.transform.localPosition.z);
//ropeShooter.GetComponent<Rigidbody2D> ().AddForce (ropeShooter.transform.up*upForce);
SpringJoint2D newRope = ropeShooter.AddComponent<SpringJoint2D> ();
newRope.enableCollision = false;
newRope.frequency = stretchPower;
newRope.connectedAnchor = anchorPosition;
newRope.autoConfigureDistance = false;
newRope.distance = 0.5f;
newRope.enabled = true;
GameObject.DestroyImmediate (rope);
rope = newRope;
ropeFrameCount = 0;
}
Comment
Your answer