# Re: DT in BGT

@CAE,

I've created a script that I want to contain all of my math functions that are going to be used across the code. I want to be able to call the math functions from anywhere else in the code and just plug in the relevant parameters. I don't want to have to repeat code. For example, I've created a function that will convert radians to degrees, and one to convert degrees to radians. I'm going to need ones to add, subtract, multiply and divide vectors, and one that will calculate the magnitude of vectors. If I remember correctly, the formula is A^2+B^2 = C^2 for 2d, and A^2+B^2+C^2 for 3d magnitude calculations. I want to be able to make these calculations on the fly, so I need to figure out a way to make it so that they will take values from any vector. In other words, I want the functions to be generic and able to perform calculations on any vector I pass it as a parameter. For example, like this, magnitud
e calculation:

float GetMag(vector)

{

return mag = square_root(vector.A*A+B*B+C*C);

}

Then, in other code I can just say:

GetMag(velocity), or GetMag(direction), GetMag(Whatever), etc. I should be able to do the same with the other arithmetic operations as well, like float Add(vector), float sub(vector), etc. Am I doing that correctly, or is there a different way to implement that?

Next question. I have implemented the ability for the player to choos the angle of his shot...anywhere from 0 degrees straight ahead to 90 degrees to the right, and from 270 degrees to the left, through 359 degrees back to straight ahead. So let's say as a player I want a shot of 25 degrees...not straight ahead, but not directly diagonally, or maybe I want a sharper angle across the grid, say 75 degrees...not directly straight to the right, but more than diagonally. So once I choose, how do I then have the ball move at that actual angle
? Let's say I'm mad because you just scored on me, so now I want you to have to run your ass off for the ball, so let's say I choose 75 degrees. A 45-degree angle, or 0.78552 radians, would be a 1:1 ratio, x to y movement. With a 75-degree angle, or 1.3092 radians, the ball would move more along x than y, but would still move on both axes. Having both of those numbers, what is the best way of incorporating that into a vector to tell the ball to move at that angle, and have it calculate exactly how much to move along x and y to accomplish that? Thanks.

JLove

_______________________________________________ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector## Advertising