Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add consintent speed/velocity to a rope?
#1
I tried with this:



private void AddVelocityToRope(float scale)
{
    var verticalActionValue = Input.GetAxisRaw("Vertical");
    var shiftPressed = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

    if (verticalActionValue != 0 && shiftPressed)
    {
        var downPressed = verticalActionValue < 0;
        var s = 1;
        if (downPressed) s = -1;
        var bodyForward = _playerController.animator.bodyRotation * Vector3.forward * s;

        //SetRopeInvMasses(1 / mass);

        //igy egyenesebb a kotel mozgasa, mintha csak 1-et adnank at
        for (var i = 0; i < rope.elements.Count; i++)
        {
            var addVelocity = (bodyForward * (scale * 10f * maxRopeVelocityScale)).ToVector4();
            var v = solver.velocities[rope.elements[i].particle2];
            if (v.magnitude <= _newDamping * 2) solver.velocities[rope.elements[i].particle2] += addVelocity * (Time.deltaTime * 10);
        }
    }
}




But I get not the desitred behaviour.



So how can I add a consistent velocity to all my particles?



+1: How can I ignore bigger velocities than a limit? Sometimes just the rope immediatelly get a big velocity I don't know why...and the rope is just jumping..
Reply
#2
(04-10-2023, 05:16 PM)lacasrac Wrote: But I get not the desitred behaviour.

Hi!

Well, what's the desired behavior? (and what do you get instead?)


(04-10-2023, 05:16 PM)lacasrac Wrote: So how can I add a consistent velocity to all my particles?

What do you mean by "consistent"? Adding to an object's velocity is an acceleration. Do you mean constant acceleration?

(04-10-2023, 05:16 PM)lacasrac Wrote: +1: How can I ignore bigger velocities than a limit? Sometimes just the rope immediatelly get a big velocity I don't know why...and the rope is just jumping..

You should try to find the cause of the high velocity, that's better than limiting velocities in an attempt to hide the symptom. These are often due to constraint fighting (that is, multiple constraints trying to enforce mutually exclusive conditions). This typically arises when attaching ropes inside a collider, since the rope can't simultaneously be inside and outside the collider. The solution in this case is to use collision filters to prevent the offending rope section from colliding against the object it's attached to.

If you want to cap velocities to not exceed a threshold anyway, you can use Vector3.ClampMagnitude

kind regards
Reply