Re: Need help and opinion on tank game problem
In mathematics, angle "0" generally points right, and then rotates counter-clockwise (i.e. it goes "up" from that point). So I guess I can see why Clickteam decided they'd do sprite rotation this way.
However, on a computer screen, (0,0) is the upper-left corner, and (contrary to traditional mathematical coordinate systems) the Y value increases in the down direction. The original reason for this is because a computer monitor draws pixels from top to bottom.
Personally, I think that Clickteam should have made the sprite rotation consistent with the flipped y-axis... but what's done is done, and if they changed it now, they'd break everyone's code. :P
Re: Need help and opinion on tank game problem
I'm not sure I understand the math behind this, so you are using atan to get the angles of two points and are adding them together to get the angle of the slope?
-Variant
Re: Need help and opinion on tank game problem
Quote:
Originally Posted by variant
I'm not sure I understand the math behind this, so you are using atan to get the angles of two points and are adding them together to get the angle of the slope?
-Variant
No, that's not it.
What I'm doing is subtracting the vector "wheel1" from the vector "wheel2" to get a new vector that points from one wheel to the other. Hopefully this picture should help:
http://img696.imageshack.us/img696/3977/wheels.png
The X-component of this vector is X("wheel2")-X("wheel1").
The Y-component of this vector is Y("wheel2")-Y("wheel1").
If I feed this vector into atan2, it'll give me the angle of the vector (which gives us the angle from wheel1 to wheel2).
Sorry if that makes it more confusing. That's just the way I look at it.
Altenatively, I think the Advanced Direction object has an "angle from point A to point B" function.
Re: Need help and opinion on tank game problem
So your finding the distance between two wheels and setting the angle to the angle of the line connecting the two wheels?
-Thanks, Variant
Re: Need help and opinion on tank game problem
In Euclidean geometry, a "vector" is an entity that has a magnitude and direction. It's one of the most useful mathematical concepts that a game programmer can be familiar with.
A vector is technically a magnitude and direction, but most of the time we write it as its x component and y component. For example, some random vector V could be (45,-2.34). It's kind of like an X,Y coordinate, but you should think of it as a magnitude and direction.
There are basic rules of vector math that are useful for game programming. For example:
(a,b) - (c,d) = (a-c, b-d)
That's the rule I used to find a vector that points from wheel1 to wheel2. I'm not technically finding the distance between the two wheels. I'm finding a vector that points from one wheel to another.
Once I find that, I can just plug the vector's components into the atan2 function and it'll churn out the angle of the vector.
Re: Need help and opinion on tank game problem
Quote:
Originally Posted by UltimateWalrus
In Euclidean geometry, a "vector" is an entity that has a magnitude and direction. It's one of the most useful mathematical concepts that a game programmer can be familiar with.
A vector is technically a magnitude and direction, but most of the time we write it as its x component and y component. For example, some random vector V could be (45,-2.34). It's kind of like an X,Y coordinate, but you should think of it as a magnitude and direction.
There are basic rules of vector math that are useful for game programming. For example:
(a,b) - (c,d) = (a-c, b-d)
That's the rule I used to find a vector that points from wheel1 to wheel2. I'm not technically finding the distance between the two wheels. I'm finding a vector that points from one wheel to another.
Once I find that, I can just plug the vector's components into the atan2 function and it'll churn out the angle of the vector.
I understand the concept and the process pretty well, but I struggle to understand what a "vector" is. The only thing I've used atan for is for my player to "look" at the mouse or some other object.
-Thanks, Variant
Re: Need help and opinion on tank game problem
Well, another way of looking at it is that I'm making the first wheel "look" at the second wheel. Except instead of setting the wheel's angle, I'd set the tank's angle.
Here are some helpful vector explanations, if you're still curious:
http://mathforum.org/library/drmath/sets/select/dm_vectors.html
Re: Need help and opinion on tank game problem
Quote:
Originally Posted by UltimateWalrus
Well, another way of looking at it is that I'm making the first wheel "look" at the second wheel. Except instead of setting the wheel's angle, I'd set the tank's angle.
Here are some helpful vector explanations, if you're still curious:
http://mathforum.org/library/drmath/sets/select/dm_vectors.html
Now that makes sense. I'll remember this when I make moving vehicles. It is amazing what math can do! Thanks!
-Variant
Re: Need help and opinion on tank game problem
Thanks UltimateWalrus, that helps a lot. When I have time I'll go back and plug that in :)
Re: Need help and opinion on tank game problem
Quote:
Originally Posted by UltimateWalrus
The exact expression you should use looks something like this:
Tank sprite --- Set Angle to:
-1*ATan2(Y("wheel2")-Y( "wheel1" ), X("wheel2")-X( "wheel1" ))
Okay I'm having a syntax error, and I'm not exactly sure what you are doing at the comma here. How do I make this into a valid equation in the MMF2 expression editor?