Search In
• More options...
Find results that contain...
Find results in...

# I'm at my wits end.

## Recommended Posts

I have a maths problem. I've googled my eyes out, but I can't find what I want. Basically all I'd like some help with is how to find the direction of travel, in degrees, from an object's x/y velocity.

Just make a right-angled triangle, and use pythagoras/trig to work out the angle. Simple.

I'm goddamn useless at math, and I have been (and very likely will be) forever. How do I make the right angled triangle? For instance, if I had an object with an x-velocity of -40 and a y-velocity of 30, how would I calculate the triangle?

And since it's for a doom level, I didn't think it was in the wrong forum.... Perhaps questions would have been better though.

cos(vector angle) * vector length = x component

sin(vector angle) * vector length = y component

vector length = (x^2 + y^2)^0.5 = 50

cos(vector angle) * vector length = x
sin(vector angle) * vector length = y

vector angle = acos(x / vector length)
vector angle = asin(y / vector length)

cos(vector angle) * 50 = -40
sin(vector angle) * 50 = 30

vector angle = acos(-40/50) or pi - acos(-40/50)
vector angle = asin(30/50) or pi - asin(30/50)

Since there there are two solutions to solving sin and cos, you'll have to determine which one to go by depending on what you plan to do.

Starting from a vector instead of x and y velocities is probably easier.

ToXiCFLUFF said:

I'm goddamn useless at math, and I have been (and very likely will be) forever. How do I make the right angled triangle? For instance, if I had an object with an x-velocity of -40 and a y-velocity of 30, how would I calculate the triangle?

And since it's for a doom level, I didn't think it was in the wrong forum.... Perhaps questions would have been better though.

To illustrate the point in a slightly less mathy way:

Your object travels 40 units backwards and 30 units up in one interval of time. Simply draw a coordinate axis(this is just two lines that form a + shape). Starting at the point where your two lines meet, draw a line 40 units long going left(left is negative), and a line 30 units up, and connect the endpoints. You now have a triangle. The angle the diagonal line makes with the horizontal axis is the angle you want.

Wonderful, thanks for your descriptive replies. Basically, I've done a wad-independent particle system with fragglescript - not a particularly elegant solution, but suited to my capabilities. Originally I took it from my 2D sidescroller mod, which needed it for player satellites, bullet ricochets, smoke and debris trails etc,

Which was all fine, and it was as simple as copying and pasting to get it working in a different wad. But when it came to particle types with the bouncing property, I found (obviously) that bouncing on one axis wasn't good enough. So that was why I needed a method of finding the angle of the object's movement, to determine the angle of deflection.

//Edit: Thanks guys, even a mathematically spasticated individual managed to get the bounce calculations working with this.