|
Slope of a line Displaying 1-7 of 7 total.
1
ChaliShank
|
I'm trying to make a little function that calculates how to get a spell (like a fireball) to go in a diagonal line to its target. In theory, I would use slope, but of course Verge doesn't allow fractions. Any ideas? I know some of you guys have done this before.
Thanks ladz,
ChaliShank
Posted on 2002-04-15 19:22:32
|
choris
|
Use this basic principle :
current x current time
------------ = ---------------
total x span total time span
Which simplifies to :
current x = (current time)*(total x span)/(total time span)
Need more information? Well say you want to move from coordinates (x1,y1) to (x2,y2) over a certain time period. Let 't' be the variable for the current time in the loop, and total_time be the total ammount of time the loop will take. That would look something like this :
int x1, y1, x2, y2;
int t, total_time;
int tempx, tempy;
for(t=0;tx1 and y2x1. You get the general idea? Query again if you don't.
choris@verge-rpg.com
Posted on 2002-04-15 20:08:10
|
ChaliShank
|
It's pretty clear, but how do you increment the y value of the pcx by the right amount? I was thinking maybe y1-y2/t, but still...also I can't use any sort of loop, because all the action on the screen stops, so I'll have to use a bunch of if statements. At any rate, it's almost crystal, just the y thing.
Posted on 2002-04-17 18:29:27
|
Omni
|
you could create a loop that called the processentities and render, and also any animation code as well while it displayed the number. Besides, loops are cool.
It is not wrong to not understand, for we are all ignorant, but neither is understanding pointless.
Posted on 2002-04-17 19:21:10
|
choris
|
Tell me what this is for, I'm curious. At any rate, if you're not moving it in a loop, I'm sure it can still be done. The only real difference is that you need to be able to determine the instantaneous posisition rather than move it along as you go.
void position(int startx, int starty, int endx, int endy, int current_time, int time_span)
{
int tempx, tempy;
if(endxstartx)
tempx=current_time*(endx-startx)/time_span;
else if(endxstarty)
tempy=current_time*(endy-starty)/time_span;
else if(endy
choris@verge-rpg.com
Posted on 2002-04-17 20:14:52
|
choris
|
Don't ask me how, but rather than risking it again, look here :
http://hov.verge-rpg.com/position.txt
If you can't figure out how to use timing variables to make it work, fill me in on what your exactly trying to do, and maybe I can help you better.
choris@verge-rpg.com
Posted on 2002-04-17 20:21:53
|
CypherAlmasy
|
The way I understand it, there are various ways to solve this particular problem, and they all depend on your particular game. If you only need the spell to go in a simple 45 degree line, then every couple of frames you can use entity.x[] and entity.y[] to change the position of the sprite by the same amount before you Render(). Of course, in order to do this, you probably need a HookRetraced script, which might be out of the question (again, depending on your situation). HOWEVER, if I read the post correctly, what you need is something a bit more complicated; namely, you need to get from x1,y1 to x2,y2, and the "slope" of that line isn't necessarily 1. If that's the case, you could possibly try what I did. I used a rasterization algorithm (Bresenham's algorithm) to calculate the various positions the sprite (in your case, a fireball) would need to be, then used a HookRetraced script to move the sprite to these points (I call them nodes) until it got there. If you want more info, feel free to email me (AmerikaJinDesu@hotmail.com or mweir@mainex1.asu.edu)Once I get my tech demo of Project B.O.B. out, you could also take a look at my move.vc. Anyway, it's 3:00 in the morning and I need some sleep 'fore I go to work. Good luck.
CypherAlmasy
"If it weren't for my horse (as in giddyup, giddyup, let's go), I wouldn't have spent that year in college (a degree granting institution)."
-Lewis Black
Posted on 2002-05-20 05:06:21
|
Displaying 1-7 of 7 total.
1
|
|