Sticky Conveyor Belt

Viewed 124

I'm working on having a sticky conveyor belt, so that objects can also go around it. But my objects currently get stuck half way, as seen in the picture.

enter image description here

This is the movement code of the conveyor belt.

private void HandleCargo()
{
    var _speed = speed * Time.deltaTime;
    foreach (var cargo in _cargo)
    {
        var change = cargo.Key.transform.right * _speed;
        cargo.Key.transform.Translate(change);
    }
}

And the code taking care of the rotation to the surface.

private void Update()
{
    Debug.DrawRay(transform.position, -transform.up, Color.black);

    if (!Physics.Raycast(transform.position, -transform.up, out var hit, _distance)) return;
    var normal = hit.normal;

    transform.up -= (transform.up - hit.normal) * 0.05f;
}

If someone has pointers as to why this happens, that would be great. I kind of have an idea, since the transform right of the conveyor code is pointing inwards at this angles so the movement doesn't happen around the belt anymore, but I exhausted my attempts to fix it...

0 Answers
Related