Hello guys,
I am trying to make a turn based game that use similar control mechanic as Steambird survival on iOS. Basically, I want players to be able to draw a line/curve from their character, and at the end of the turn the character would move, following that line.
There are several requirements for the control:
- The line/curve has to have a specified length (which is different between various characters)
- The line/curve has to have a minimum angle (which is different between various characters)
- When player slides their finger outside the maximum length of the curve, the curve stops being drawn, but if players move their finger towards a different position, the angle of the curve will keep changing according to the new position of their finger. Exactly like the Steambird game.
I have been stuck at this problem for more than 2 weeks.
What I have done is the following: (The triangle is the character, facing upwards in this example).
- Calculate the blue lines (normal and forward direction of the triangle).
- Calculate the orange line (line between the triangle and the user’s finger).
- Calculate the mid point of the orange line (green point).
- Draw a line normal to the orange line that passes through the green point (green line).
- Find the intersection of the green line and the normal blue line. This is the centre of the circle (black circle).
- Having the centre, I can now start to draw a circle from the triangle position up to the red dot (user’s finger).
The way I implemented in unity is basically calculate 10 points of the grey line, add them to a LineRenderer and draw a line between them. However, this doesn’t seem like the correct approach because I am having so many problems. To name a few:
- I cannot think of a way to limit the line length, or the angle of the circle.
- Even if I could limit the length, I don’t know how I would still adjust the line when my finger is already outside the maximum length.
- I cannot easily add and remove point from the Line renderer, which is makes the line always lag behind the finger at high finger speeds.
- And I haven’t even consider moving the triangle following the curve.
I have attached 3 screenshots above of the Steambird game, where the red dots are where I placed my finger. As you can see, the line is still drawn in the direction of my finger, but it has a limit length.
I really think there is a better method to accomplish this behaviour, because my approach looks very complex for such a “simple” mechanic.
So the question is/are:
- Is there a better way to accomplish this behaviour? any built-in functions/components that I missed?
- If the above is not true, any algorithm or strategies or any help at all to some of the problems mentioned.
here is some of my code:
Anyway, Thank you a lot for any help that you guys can give me.