One-way linear spring, and moving static bodies

Topics: User Forum
Dec 8, 2008 at 5:40 PM
Edited Dec 8, 2008 at 10:57 PM
Hi, two questions here:

I'm trying to make a spring pull back when it's stretched, but NOT push back when it's squashed - like a bungee rope but not flexible. In other physics engines I would use a linear joint and set its 'stiffness', but I can't find the right properties to tweak. How can I achieve this?

Second, I'd like to stop a body reacting to other bodies, but still affect them, and still be moveable using forces (so making it static is not an option). For example, the paddles in Pong aren't affected by the ball, but the ball can still bounce off them, and they are moveable. I've tried adjusting the LinearDragCoefficient, but no matter how high I set it it's always affected by other bodies very slightly.

Thanks for your time.


Dec 9, 2008 at 10:34 AM
Second one:
Turning on the IgnoreGravity for the Body and make it's Mass extremely high comparing to all other Bodies could probably work. Although I haven't tried it.
Dec 9, 2008 at 1:51 PM
I gave it a shot, it always moves a microscopic amount, but still enough to be a problem.

If I change the mass to extremely high values (1000+) I get unpredicatable results, like the object flying out of view very quickly.
Dec 9, 2008 at 2:41 PM
You can also try a FixedRevoluteJoint and an FixedAngleJoint, thus if you change the world anchor of the FixedRevoluteJoint the object will move to this position by getting the necessary impulses applied to hold it's location. And also setting IgnoreGravity=true; will be a good choice. ;-)
Dec 9, 2008 at 3:13 PM
Edited Dec 9, 2008 at 3:14 PM
This was my first attempt, but changing the anchor didn't move the object, it just made the object sink slowly and rotate (even with the FixedAngleJoint in place).

EDIT: All this is with IgnoreGravity set to true.
Dec 9, 2008 at 3:58 PM
The anchor is a Joints sort of "rotation point", not it's position.
You need to change the body.Position value to move it's position.
Dec 9, 2008 at 6:15 PM
Uh oh... sry I just looked at the top of the FixedRevoluteJoint-file...
By adding the property:
public Vector2 WorldAnchor
{
    get { return _anchor; }
    set
    {
        _anchor = value;
    }
}
to FixedRevoluteJoint I think you can achieve what you want to do.

Another way was to use a normal RevoluteJoint with an Object(IsStatic = true; CollisionResponseEnabled = false;) and moving this object.
Dec 9, 2008 at 8:07 PM
"You need to change the body.Position value to move it's position"

This sort of worked, but gave me unpredicatable collision, almost as if I were trying to manually move the paddle's body itself.

"Another way was to use a normal RevoluteJoint with an Object(IsStatic = true; CollisionResponseEnabled = false;) and moving this object."

Yes! This is almost there. The only problem is the paddle still turns very slightly when hit, as if the Angular join isn't doing it's job properly. It corrects itself immediately, so it's not a big issue, but if someone could shed some light on why the Angular join doesn't behave, it I would appreciate it.

Dec 10, 2008 at 10:40 AM
Edited Dec 10, 2008 at 10:41 AM
@deadstar: I think it's because the body collides with another body and on the next frame the FixedAngularJoint can react on this change by applying a torque. A workaround is to draw your Sprite always with the targetangle of the FixedAngularJoint, thus the player can't see that the object is rotating.