# HingeJoint2D Teleportation

I’m making a game where the character sways back and forth on a hinge joint, and when the player presses space, it releases the hinge joint, and fires you in the direction you were pointing when you pressed space. I have a circle collider on the player, and I have a statement that checks for when the player is upright after rolling for a while. What I’m trying to get it to do is when the player rolls into an upright position, I want it to reset the hinge joint at that location, right under the player’s feet (at the groundCheck pos). What it ends up doing is teleporting the character very far along the x axis. Help? Thanks!

Code:

``````public HingeJoint2D hinge;
public float force = 150f;

private JointMotor2D motor;
private JointAngleLimits2D limits;

public Transform groundCheck;
private bool grounded = false;

private bool anchorDone = false;

public float speed;

void Start () {
//Motor changer
motor = hinge.motor;
limits = hinge.limits;
limits.min = -30;
limits.max = 30;
}

void FixedUpdate () {
//Ground checking

//Wobbling
if(hinge.limitState == JointLimitState2D.UpperLimit) {
motor.motorSpeed = -force;

hinge.motor = motor;
} else if (hinge.limitState == JointLimitState2D.LowerLimit) {
motor.motorSpeed = force;

hinge.motor = motor;
}

//Jump
if (grounded && Input.GetKeyDown(KeyCode.Space)) {
hinge.enabled = false;

anchorDone = false;
grounded = false;
}
}

void Update () {
//Reset wobble
if (grounded && !anchorDone) {
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.identity, speed * Time.deltaTime);

if (transform.rotation == Quaternion.identity) {
hinge.limits = limits;
hinge.anchor = groundCheck.position;
hinge.connectedAnchor = groundCheck.position;
hinge.enabled = true;

anchorDone = true;
}
}
}
``````

Picture of what is happening when you become upright:[30088-screen+shot+2014-07-30+at+1.30.57+pm.png|30088]

SOLVED I had the a random rigidbody2d attached… Derp.