How to create an illusion of a rope extending in 2D

I’m currently in the process of developing game and I ran into a little bit of a challenge that I cannot find a solution to (an efficient and effective one atlas). What I’m trying to currently do, is to create the effect of a rope extending in one direction. Imagine spiderman shooting his web. Im not looking for rope physics, I would just like to know how I can make it so that a rope extends from an object to another object over time without being distorted in size.

One solution I came up with is to put the rope behind another object in the z axis and than move it vertically in the y axis until it moves above the object in front of it. This creating an illusion as if the rope is extending vertically. Only problem with this solution is that the object in front of the rope in the z axis must be invisible but still not show the rope below the point where I don’t want it seen.

If anyone has experience with doing something like this I would highly appreciate your advice as I’m quite new to game design.

Can’t you just scale the object? If you set the pivot point at the position you want the rope to start from, rotate it in the direction you want it to extend and then scale it in one direction…

Thats what I originally did, but it distorts the sprite the larger it is extended or scaled.

I think you might be using the texture scale so that the texture is displayed repeatedly?

What I was doing originally is this(Which I found in another post):

  • //Scale the object on X axis in local units
  • transform.localScale.x += scaleAmmount;
  • //Move the object on X axis in local units
  • transform.localPosition += scaleAmmount/2;

But by increasing the localScale, and therefore the proportion of the resolution the object becomes very blurry and distorted.

Ah, I’ve worded my response incorrectly. What I actually meant to say is that I think you might want to be using the texture scale. Meaning, scale up your object as you normally would, but at the same time modify the texture scale so that the texture stays at the same size per world unit, but instead it would repeat itself along the object.

1 Like

Ill look into it thanks!

Do you know of any sources which can teach me how to do this?

Unfortunately no, but I think the computation would be rather trivial. For example, if you scale the object by 2, the texture scale should be 2 as well. Or is it 0.5? I haven’t actually tried the whole thing, it’s just an idea :slight_smile:

If anyone’s wondering about this issue, I’ve managed to do it using a spriterenderer with “tiled” draw mode. You don’t want to rescale the transform, you want to change the dimensions of the sprite itself. In the code you’ll need to compensate its position. Basically increasing its width by 2 means you need to move the object towards the target by 1 so it looks like it has that point of origin. It extends from the left so you wanna rotate it and always scale it towards the “right”. I recommend placing it inside an empty gameobject that acts as the origin of the rope if it’s gonna rotate.
And make sure to use a “full rect” mesh type on the sprite