Computer Science Canada Line direction |
Author: | Flikerator [ Fri Feb 18, 2005 7:23 pm ] | ||
Post subject: | Line direction | ||
I want the line to try and go towards the mouse, like it is now. But only draw about 20 pixels (Give or take) towards it and then stop. Does anyone know how to do that?
|
Author: | Neo [ Fri Feb 18, 2005 8:03 pm ] |
Post subject: | |
Do you want a really easy way out? Draw a black circle where the mouse pointer is after youve drawn the line. ![]() |
Author: | Flikerator [ Fri Feb 18, 2005 9:10 pm ] |
Post subject: | |
No because I will have many different backgrounds ![]() (Not just colours, like actually pictured backgrounds. |
Author: | Flikerator [ Sat Feb 19, 2005 9:17 am ] |
Post subject: | |
Can someone help me out here? |
Author: | Martin [ Sat Feb 19, 2005 10:02 am ] |
Post subject: | |
Sure. It's easy with a bit of trig. So let's say that you want your line to be of length L and the start and end points are (x1, y1) and (x2, y2) respectively. Now, you can calculate the length of line (x1, y1, x2, y2) with pythagarus easily enough. Let's call that M. Now you can draw a line (x1, y1, x2, y2) easily, but you want a line that is a stretch of that line. That is, you want a line that is scaled by a factor of 'L/M' So your line will be: (x1, y1, x1 + (x2 - x1) * (L/M), y1 + (y2 - y1) * (L/M)) Hope it helps. |
Author: | Drakain Zeil [ Sat Feb 19, 2005 10:02 am ] |
Post subject: | |
Math.Distance ? |
Author: | Flikerator [ Sat Feb 19, 2005 11:47 am ] | ||
Post subject: | |||
Alright when I read that M/L thing this is what I came up with. It doesn't work correctly because both my "M" and "L" are the same. Which one do I change and how? |
Author: | Martin [ Sat Feb 19, 2005 1:42 pm ] |
Post subject: | |
Don't use div. Divide, multiply and then round the result down. 20 * (2 div 4) = 0, but round (20 * (2/4)) = 10 |
Author: | Flikerator [ Sat Feb 19, 2005 2:32 pm ] |
Post subject: | |
What absolutely must I change. Because I changed the div to "/" and tried a phew other things but im still just stabbing in the dark at what to do. Thanks for all the help though ![]() |
Author: | Flikerator [ Sat Feb 19, 2005 5:03 pm ] |
Post subject: | |
Cervantes helped me out. We gots it to work yay ^^ Looks awsome too ![]() I also added a sprint feature with energy : D So I can add that into my zombie game. |
Author: | Flikerator [ Fri Feb 25, 2005 6:58 pm ] | ||
Post subject: | |||
Ive been working on this for half an hour or so. It is probably a really easy answer but I can't figure it out. I need it to face the opposite direction of the mouse but only go a certain length. I already have it going towards it but I need it to go away. If you need me to post more of the code just say so.
|
Author: | Cervantes [ Fri Feb 25, 2005 7:19 pm ] | ||
Post subject: | |||
30 minutes? That sucks. ![]() It's the same code, just subtract the round ((x2 - x1) stuff instead of add it. Same with y.
|