- #1
Zoltan
- 6
- 0
Hi, i got problem i am trying to solve.
Basicly i got point moving along bunch of lines ( either rectangles/triangles it is custom, generated in code ).
I am using this equation to find out x,y coordinates for moving along specific line :
(its taken from code )
x = x1 + center.x + (x2 - x1) * p
y = y1 + center.y + (y2 - y1) * p
center is there just to adjust the whole shape
p is basicly the increment for moving the point on the line.
Now i got logic to move between the different lines, by just figuring out if the p is over 1 switch to next line. Thats all fine and dandy.
But here comes the problem. Each of the p increments are same each frame, i.e. 0.1,0.2,0.3,0.4 it means that no matter how long the line is it always takes same amount of time to finish. Because 0.1 distance represents 10% of length of the line, it would move 10% of the line distance.
Now i can fix this with just dividing the p basicly by the length of the line, thus all the movement on all lines is same. If you would have triangle with two really long lines and one really small. You would have really fast movement on the two long lines and really slow movement on the small with the 10% movement per frame. But that's what i don't want :) I want the speed to be same on each of the line while mainting same amount of time it took to finish movement on whole shape before normalising it.
I do that by dividing the increment by the line distance, its working fine, but the speed is mush slower obviously. ( Example, if you would have increment 1 unit per frame and length of line was 10 units, speed would be 0.1, but problem is you got 3 different lines and the speed needs to adjusted so that it takes same amount of time as before this length division )
I tried things like take circumference of the whole shape, dividing it by amount of sides and using it that value to multiple the speed. Wrong
I tried this equation when the shape was triangle :
(x/a + x/b +x/c) * y = 3x
x = increment
y = desired multiplication of the speed
it basicly says if u have 3 frames movement, one at each of the side of the triangle with the normalised increment, if you mulitple that by some value, you get equal amount to original increments in 3 frames 1 = 1. Wrong ! value doesn't work
So, i am not sure if its clear or not :) I am not too good in explaining stuff. But if you can help me with the problem in any way, i would very very grateful. Any suggestions welcomed. Thank you for your time taken to read it all this.
Zoltan
Edit:
I realized i probably should have factor how long the point is on each of the line so i adjusted the equation like this:
((x/a * a/t) + (x/b * b/t) + (x/c * c/t)) * y = x
t = circumference of the shape (triangle)
Still not working tho.
Basicly i got point moving along bunch of lines ( either rectangles/triangles it is custom, generated in code ).
I am using this equation to find out x,y coordinates for moving along specific line :
(its taken from code )
x = x1 + center.x + (x2 - x1) * p
y = y1 + center.y + (y2 - y1) * p
center is there just to adjust the whole shape
p is basicly the increment for moving the point on the line.
Now i got logic to move between the different lines, by just figuring out if the p is over 1 switch to next line. Thats all fine and dandy.
But here comes the problem. Each of the p increments are same each frame, i.e. 0.1,0.2,0.3,0.4 it means that no matter how long the line is it always takes same amount of time to finish. Because 0.1 distance represents 10% of length of the line, it would move 10% of the line distance.
Now i can fix this with just dividing the p basicly by the length of the line, thus all the movement on all lines is same. If you would have triangle with two really long lines and one really small. You would have really fast movement on the two long lines and really slow movement on the small with the 10% movement per frame. But that's what i don't want :) I want the speed to be same on each of the line while mainting same amount of time it took to finish movement on whole shape before normalising it.
I do that by dividing the increment by the line distance, its working fine, but the speed is mush slower obviously. ( Example, if you would have increment 1 unit per frame and length of line was 10 units, speed would be 0.1, but problem is you got 3 different lines and the speed needs to adjusted so that it takes same amount of time as before this length division )
I tried things like take circumference of the whole shape, dividing it by amount of sides and using it that value to multiple the speed. Wrong
I tried this equation when the shape was triangle :
(x/a + x/b +x/c) * y = 3x
x = increment
y = desired multiplication of the speed
it basicly says if u have 3 frames movement, one at each of the side of the triangle with the normalised increment, if you mulitple that by some value, you get equal amount to original increments in 3 frames 1 = 1. Wrong ! value doesn't work
So, i am not sure if its clear or not :) I am not too good in explaining stuff. But if you can help me with the problem in any way, i would very very grateful. Any suggestions welcomed. Thank you for your time taken to read it all this.
Zoltan
Edit:
I realized i probably should have factor how long the point is on each of the line so i adjusted the equation like this:
((x/a * a/t) + (x/b * b/t) + (x/c * c/t)) * y = x
t = circumference of the shape (triangle)
Still not working tho.
Last edited: