Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Better rope pendulum
Hello again!

I created this pendulum, found that script on the net and refactored it to obi rope.

By the way it looks like very weird. How can I create a more nicer look?

script is here:

public class ObiRopePendulum : MonoBehaviour
    [Range(0.3f, 10)] public float moveSpeed = 0.8f;
    [Range(5f, 40)] public float angleScale = 20f;
    private float _leftAngle = -10;
    private float _rightAngle = 10;
    private bool _clockwise;
    private CreateObiRope _createObiRope;

    private void Start()
        _createObiRope = GetComponent<CreateObiRope>();
        _clockwise = true;
        _rightAngle = moveSpeed * angleScale;
        _leftAngle = -_rightAngle;

    private void Update() => Move();

    private void Move()
        var angle = _createObiRope.GetSignedRopeAngle();
        if (angle > _rightAngle)
            _clockwise = false;
        if (angle < _leftAngle)
            _clockwise = true;
        var speed = !_clockwise ? moveSpeed : -moveSpeed;
        var v = new Vector3(speed, 0, 0);

and the PendulumVelocity:

public void PendulumVelocity(Vector3 velocity)
    var lpIndex1 = GetFirstParticleIndex();
    var lpIndex2 = GetLastParticleIndex();
    for (var i = lpIndex1; i <= lpIndex2; i++)
        rope.solver.velocities[i] = velocity.ToVector4();     
[i]    }*/
    rope.solver.velocities[GetLastParticleIndex()] = velocity.ToVector4();

I want the lamp swinging always left/right but with a physics correct way.

How can I improve it to a better way? It is now not so good at the moment Triste
(04-11-2021, 08:06 AM)lacasrac Wrote: How can I improve it to a better way? It is now not so good at the moment Triste

Mass is really important in pendulums. What's the mass of each rope particle, and the mass of the objects at its end? Right now it looks like the weight at the end has similar (or less) mass than the rope. This results in the rope swinging freely (as if nothing was attached to it) and the object at the end is so light that it just gets carried by the rope effortlessly: think of a paper ball attached at the end of a iron chain.

The object at the end should be heavy enough for the rope to be taut, and be able to drive the rope movement.

Needless to say, the object at the end must be a non-kinematic rigidbody attached to the rope using a dynamic attachment. Otherwise the rope will just ignore the object and move on its own, so you won't have a pendulum but merely a rope. Your code looks like it just applies some velocity to the last particle: this isn't a pendulum and won't behave like one no matter how much you try. See:

Quote:A simple pendulum consists of a relatively massive object hung by a string from a fixed support. It typically hangs vertically in its equilibrium position. The massive object is affectionately referred to as the pendulum bob. When the bob is displaced from equilibrium and then released, it begins its back and forth vibration about its fixed equilibrium position.

Edit: Here's a video comparing a pendulum where the object at the end is heavier than the rope (left one) and another one where both have the same mass (right one). As you can see the left one swings much more nicely and the rope is kept taut at all times.