WeldJoint problem

Posts regarding potential bugs, enhancement requests, and general feedback on use of dyn4j
coldf
Posts: 2
Joined: Wed Jul 12, 2017 6:15 am

WeldJoint problem

Postby coldf » Wed Jul 12, 2017 6:30 am

So I've been trying to weld two objects together. However, when one moves to the side and makes the structure rotate, there is a slight position offset. The two objects aren't exactly constrained together.

Image

Any idea of a fix to get rid of this ?

William
Site Admin
Posts: 339
Joined: Sat Feb 06, 2010 10:23 pm

Re: WeldJoint problem

Postby William » Fri Jul 14, 2017 9:34 pm

The WeldJoint will have some movement like that but I wouldn't expect that much. Can you show the code producing this problem?

Just to confirm, do you need the joint? The best use of the WeldJoint is to temporarily have a body joined with another. If you want them attached all the time, you can just add both of them as fixtures to a single body.

William

coldf
Posts: 2
Joined: Wed Jul 12, 2017 6:15 am

Re: WeldJoint problem

Postby coldf » Sat Jul 15, 2017 5:04 am

William wrote:The WeldJoint will have some movement like that but I wouldn't expect that much. Can you show the code producing this problem?

Just to confirm, do you need the joint? The best use of the WeldJoint is to temporarily have a body joined with another. If you want them attached all the time, you can just add both of them as fixtures to a single body.

William


Hi William

This is the code which is concerned by the problem:

In the moving object's class:
public void update(double deltaTime){
super.update(deltaTime);
if (GLFW.glfwGetKey(DisplayRegistry.displayWindowID, GLFW.GLFW_KEY_T) == GLFW.GLFW_PRESS){
this.getBody().applyForce(new Vector2(0D, 10D*getMass()));
}else if (GLFW.glfwGetKey(DisplayRegistry.displayWindowID, GLFW.GLFW_KEY_G) == GLFW.GLFW_PRESS){
this.getBody().applyForce(new Vector2(0D, -10D*getMass()));

}else if (GLFW.glfwGetKey(DisplayRegistry.displayWindowID, GLFW.GLFW_KEY_F) == GLFW.GLFW_PRESS){
this.getBody().applyForce(new Vector2(-10D*getMass(), 0D));

}else if (GLFW.glfwGetKey(DisplayRegistry.displayWindowID, GLFW.GLFW_KEY_H) == GLFW.GLFW_PRESS){
this.getBody().applyForce(new Vector2(10D*getMass(), 0D));
}
}

In another class:
WeldJoint wJ = new WeldJoint(obj1.getBody(), obj2.getBody(), new Vector2(0.5D,0.5));
sceneInstance.instanceWorld.addJoint(wJ);

The first body is at position 0,0 and the second at 0,1. Only the body of obj1 will move at each update.

And yes I think I will do what you have said, because I will indeed need to keep them attached all the time. Thanks William


Return to “Bugs, Enhancements, Feedback”

Who is online

Users browsing this forum: No registered users and 1 guest