- Home /
Unexpected behaviour with Fixed Joint 2D
I'm a complete newbie - trying out a 2D top-down game as a way to learn Unity.
I have two game objects connected by a Fixed Joint 2D with some damping (damping ratio 0.4, frequency 2) and this seems to work well - until the tank rotates past the 180 deg angle. At this point the joint gets confused and swings round 360 deg in the opposite direction to get back to the same point.
I've made a little video of this as the game plays. See YouTube video at link below: https://youtu.be/0d8DD3YWTcI
Not sure how to share the unity set-up so here is a screenshot of one of the objects in Inspector:
Here is the part of the script that controls the tank itself:
void Update ()
{
float forwardSpeed = Input.GetAxis ("Vertical") * maxForwardSpeed;
float rotationSpeed = Input.GetAxis ("Horizontal") * maxRotationSpeed;
direction -= rotationSpeed * Time.deltaTime;
# TODO: $$anonymous$$ove solid rigidbodies by changing their velocity ins$$anonymous$$d of changing their position.
transform.position = transform.position + transform.up * forwardSpeed * Time.deltaTime;
transform.rotation = Quaternion.Euler (0, 0, direction);
}
Your answer
Follow this Question
Related Questions
Anchored Rotation with Gradual Movement 0 Answers
is it possible to join objects along two points? 0 Answers
Blocking object from going through colliders (no rigidbody) [2D] 1 Answer
Enemy AI for top down shooter 3 Answers
Sprites performance issue 0 Answers