How to adjust sprite size

Godot Version

4.4

Question

I have a sprite map with 8 pictures to make animation. Animation itself works nicely

I am able to use this sprite in Scene that will keep moving using Direction and I am able to set Rotation properly. (so it flies from attacking unit to defending unit)
The problem is that instead of moving this Scene, I want to make the sprite to appear between attacking unit and defending unit, so the animation can play and then damage will be done.

How to such effect? I was looking into Raycast2D, Line2D but could not find a way to resize the sprite and play the animation in such cases.
To sum it up, I have:
Target Position (+global position if needed)
Attacker Position (+global position if needed)
Rotation so sprite will be pointed from attacker to target
Direction from attacker to target which I would use if this was regular projectile

I somehow need to rescale the sprite so thunder is between target and attacker positions. And it does not move, just play animation

Im on my phone not computer or id write up the code, and i could be wrong. But i would try:
Get the midpoint between your 2 points (target position - attacker position) then divide that by 2 to get halfway. Make that your sprite position (as long as your sprite offset is in the middle of the sprite. Set the ration of the sprite (which you said you can do so ill skip that part. Then calculate the distance between the points with
(target position -attacker position).length()
That will get you the distance between the 2. Then you need to know the length of your sprite. So if its 100 and you have a length between the 2 points of 250 you would change the scale by 250/100 which would be 2.5 So whatever length you get from .length() divide it by the length of your sprite. And if you dont like scaling the entire lightning bolt because it would be thicker do just scale.x or scale.y
Hope that makes sense and hope its what ur asking for!

thank you, this sounds like good idea, will try it tonight :slight_smile:

1 Like

You might also want to tweak the sprite a bit; the gaps between the end of the lightning and the edge of the sprite will scale too.

You could also try Line2D with a repeat texture…

thank you both.

I tried first solution and now thunderbolts blast the target mercilessly.
I also updated sprites based on what Hexgrid wrote.

if anyone is looking to solve similar problem, the final piece was
position_between = target_position.lerp(attacker_position, 0.5);

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.